-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use it in rust? #10
Comments
Hey, there's not a great answer for this yet, which sucks, planning to make that easier. If you're using rusqlite, you can use load_extension() to load a pre-compiled version of One day you'll be able to easily statically compile |
Yeah it's a big problem since you can't just precompile the files and place them in directory like in node modules in node. |
Also interested in that. |
Here's one way you can do it:
[package]
name = "sqlite-regex-test"
version = "0.1.0"
edition = "2021"
[dependencies]
rusqlite = {version="0.29.0", features=["bundled"]}
sqlite-regex = {git="https://github.com/asg017/sqlite-regex.git"} And use rusqlite::{ffi::sqlite3_auto_extension, Connection, Result};
use sqlite_regex::sqlite3_regex_init;
fn main() -> Result<()> {
unsafe {
let sqlite3_regex_init = std::mem::transmute(sqlite3_regex_init as *const ());
sqlite3_auto_extension(Some(sqlite3_regex_init));
}
let db = Connection::open_in_memory()?;
let (version, result): (String, i32) =
db.query_row("SELECT regex_version(), ? regexp 'a'", ["alex"], |row| {
Ok((row.get(0)?, row.get(1)?))
})?;
println!("version={version} result={result}");
Ok(())
} Requires some slightly sketch and unsafe transmuting, but works in a pinch! I'll publish this crate to https://crates.io eventually. |
The above example works with this replacement in Cargo.toml: sqlite-regex = "0.2.3-alpha.9" |
I'm using Windows 11. Tried to add May I copy and paste the error here? Other stuff in my
cargo --version
cargo 1.81.0 (2dbb1af80 2024-08-20) PS. |
Same as title
The text was updated successfully, but these errors were encountered: