Hacker News new | ask | show | jobs
Show HN: Extend MySQL with Rust (github.com)
2 points by deesix 15 days ago
MySQL has limited extensibility via plugins and components. We created a fork of MySQL with a PostgreSQL-like extension framework (VillageSQL).

Until now, all extension development was done in C++ but we know LOTS of PostgreSQL extension is done in Rust via pgrx etc.

We built a Rust SDK that allows you to natively extend MySQL with custom types and functions and a subset of the PostgreSQL extension hooks.

Steps:

cargo install cargo-vsql cargo install cargo-generate cargo generate --git https://github.com/villagesql/vsql-extension-template-rust

The actual code looks like:

use villagesql::{InValue, VdfReturn};

fn my_func(args: &[InValue]) -> VdfReturn { match args.first() { Some(InValue::String(s)) => VdfReturn::string(s.to_uppercase()), Some(InValue::Null) | None => VdfReturn::null(), _ => VdfReturn::error("my_func: expected a STRING argument"), } }

villagesql::extension! { funcs: [ villagesql::func!(my_func, "my_func", [villagesql::Type::String] -> villagesql::Type::String), ] }

Feedback welcome!