Giter Club home page Giter Club logo

Comments (11)

nyurik avatar nyurik commented on June 10, 2024 1

@asg017 thank you for all the info! I wrote sqlite-hashes crate for the static usacase using rusqlite, but I do hope that I can somehow support dynamic lib generation as well, e.g. with a feature flag of sorts.

from sqlite-loadable-rs.

asg017 avatar asg017 commented on June 10, 2024

What use case are you thinking of?

sqlite-loadable-rs could be compiled with crate-type = ["staticlib"] (in addition to the typical `"dylib" crate type), which can then be used to statically compile a SQLite extension into an application. Typically the application (your CLI, webserver, etc.) with handle both statically linking whatever sqlite version they want, in addition to statically linking any sqlite extensions they like.

I haven't blogged about it much, but it's possible to statically link a sqlite extension written with sqlite-loadable-rs into an application. For example the sqlite-regex crate can be added to your Rust projects, as described here. You add rusqlite as a separate dependency, which can statically link sqlite.

You can also use it to compile .a files, generate a .h file and use those to statically link in C/Go. I've done it before but haven't written much about it.

Is that the kind of thing you're going for?

from sqlite-loadable-rs.

nyurik avatar nyurik commented on June 10, 2024

@asg017 thank you so much for such a detailed answer!

I was thinking of doing this:

  • develop a new crate that implements md5 hashing function for sqlite
  • in my app that uses sqlx, add the md5 extension crate and statically link it (together with the sqlite)
  • my app will use query("SELECT md5(foo) ...") types of queries by loading needed extension at runtime. The sqlite DB files should not be modified just because I'm using an extra function - it should simply be an internal functionality of my app.
  • ideally, i would love to use sqlx's compile-time statement validation via a macro: query!("SELECT md5(foo) ...")
  • most importantly, the app should remain just a single binary file that contains sqlite and md5 extension

from sqlite-loadable-rs.

asg017 avatar asg017 commented on June 10, 2024

Yeah, I think statically compiling an extension written with sqlite-loadable-rs will do what you'd like! The sqlite3_auto_extension function will probably do what you'd like - you'd call that with the entrypoint of your extension that defines md5(), and any time after that, any new SQLite connection will have the md5() function available. Since everything is statically linked, it'll be a single binary, no extra loadable files needed. That sqlite-regex issue link above will be a good example to work off of.

I'm not too sure about the query!() macro however - does that mean your SQL gets compiled + executed at build time? Not familiar with sqlx.

I'll probably blog about statically linking SQLite extension in the next few weeks, and will also include an end-to-end example of statically linking in this repo soon as well.

from sqlite-loadable-rs.

asg017 avatar asg017 commented on June 10, 2024

That being said sqlite-loadable-rs might be overkill if your custom SQL functions will only be used in Rust. You're probably gonna use rusqlite anyway, and they have a create_scalar_function function that can implement a md5() function just fine. Unless you plan to also re-use your custom SQL functions in other languages (Python, Node.js, etc.), then using rusqlite/create_scalar_function will likely be simpler.

from sqlite-loadable-rs.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.