![]() ![]() ![]() However, the same can’t be done with sqlite-loadable-rs. SQLite by itself can be compiled into WASM, and you can also include extensions written in C if you compile those extensions statically before compiling with emscripten (see sqlite-lines or sqlite-path for examples). Though if you want to use an extension built with sqlite-loadable-rs in an app that uses rusqlite, consider Connection.load_extension() for dynamic loading, or Connection.handle() + sqlite3_auto_extension() for static compilation. If you already have Rust code that uses rusqlite to make scalar functions or virtual tables, you won’t be able to re-use it in sqlite-loadable-rs. If you try this and find problems, please file an issue! Doesn’t work with rusqlite If you use SQLite in “serialized mode” or with -DSQLITE_THREADSAFE=1, then I’m not sure if sqlite-loadable-rs will work as expected. I try my best to make it as safe as possible, and it’s good that SQLite itself is one of the most well-tested C codebases in the world, but you can never be sure! Maybe doesn’t work in multi-threaded environments Sqlite-loadable-rs uses the SQLite C API heavily, which means unsafe code. For example, sqlite-xsv is 1.5-1.7x faster than the “offical” CSV SQLite extension written in C, and sqlite-regex is 2x faster than the regexp extension. ![]() However, it depends on what your extension actually does - very rarely do you need a “hello world” type extension in real life. See more details at benchmarks/, but in general, a “hello world” extension built with sqlite-loadable-rs is about 10-15% slower than one built in C, and several orders of magnitude faster than extensions written in Go with riyaz-ali/sqlite (20-30x faster). To implement one in sqlite-loadable-rs, you just need to call define_scalar_function on a “callback” Rust function decorated with #, and you’ll be able to call it from SQL! Scalar functions are the simplest functions one can add to SQLite - take in values as inputs, and return a value as output. So, sqlite-loadable-rs is the first and most involved framework for writing loadable SQLite extensions in Rust! Features Scalar functions For Rust, rusqlite has had a few different PRs that attempted to add loadable extension support in that library, but none have been merged. Riyaz Ali wrote a Go library that allows one to easily write loadable extensions in Go, but it comes with a large performance cost and binary size. Historically, the main way one could create these loadable SQLite extensions were with C/C++, such as spatilite, the wonderful sqlean project, or SQLite’s official miscellaneous extensions.īut C is difficult to use safely, and integrating 3rd party libraries can be a nightmare. These are different than application-defined functions that many language clients support (such as Python’s. dll (depending on your operating system). Loadable extensions are these compiled dynamically-linked libraries, with a suffix of. These compiled dynamically-linked libraries can be loaded in any SQLite context, including the SQLite CLI, Python, Node.js, Rust, Go, and many other languages. SQLite’s runtime loadable extensions allows one to add new scalar functions, table functions, virtual tables, virtual filesystems, and more to a SQLite database connection. Still in beta, very unstable and unsafe code! Watch the repo for new releases, or follow my newsletter/RSS feed for future updates. If your company or organization finds this library useful, consider supporting my work! See Introducing sqlite-loadable-rs: A framework for building SQLite Extensions in Rust (Dec 2022) for more details! Inspired by rusqlite, pgx, and Riyaz Ali’s similar SQLite Go library. A framework for building loadable SQLite extensions in Rust. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |