Native alternative for SQLite?

I'm using SQLite for desktop applications, but in Rust it requires C wrapper that not native dependency.

Thoughts, maybe some modern alternative available?
Finally what do I want from the database:

  • storage in single file (at user profile directory)
  • transactions
  • foreign or just primary keys relations
  • async API would be good also (I/O data on background of the main UI thread)

If there is nothing better than SQLite yet, which of crates would be useful?
Also thoughts how to implement migrations from app version to version.. maybe I need some ORM wrapper, not sure. Please advice, how do you work with profile data in Rust these days

Thanks

1 Like

SQLite is still the best solution.

12 Likes

If you're worried about the dependency because of installation and build issues, see the bundled feature:

2 Likes

Despite SQLite being written in C, it is very high quality code, and it will not be easy to replicate that kind of project for anyone, in any language. That includes the original author btw, since at this point literal decades of work have gone into SQLite.

In addition to it being high quality, it is also very much battle-tested: it is used e.g. in Android, as a storage backend for apps, in Firefox and Thunderbird, in many Apple products, in Windows 10, and many more places.

11 Likes

Thanks much for replies!

If the SQLite is a really good choice for today, what about wrappers?

I found these projects looks well:

  • libsqlite3-sys - recommended above
  • sqlite - no async features from the box
  • diesel - ORM, could be useful for migrations
    • diesel-async - seems that unofficial implementation, but lot of stars on GitHub

I've used sqlx with SQLite and Postgres and have been very happy with it.

Concerning the original question, there're a few others in-memory databases, I've seen redb, recommended but never used it.

1 Like

Just as a general headsup: You likely want to avoid any async SQLite interfaces. Those come with a large performance penalty, as they try to emulate an async interface on top of the sync sqlite C API. See here for numbers.

Other than that: It's usually not a good choice to use libsqlite3-sys directly as that are the low level bindings to the c library. You should prefer rusqlite instead, which provides a high level API build on top of libsqlite3-sys

11 Likes

Thanks, both solutions looks interesting, especially redb for simple key/value storage - bookmarked so. Currently selected rusqlite, even can't say it is really high-level wrapper, especially in selection context, maybe will switch to sqlx later or diesel as supports migrations from the box.

Not sure how does it work, but found native_db crate as the wrapper for key/value redb storage. Maybe could be useful also.

It might also not be a bad idea to check out Apache DataFusion.
It's written in Rust, has FFI to eg Python, and as a project it's kind of like a Swiss army knife for tabular data, or alternatively, "what if we pull apart a DB into its constituent parts and offer those as a library?".
We're using it at $WORK and all things considered I'm pretty impressed by what it can do.

3 Likes

I just stumbled upon this while reading a blog post where people use it to query columnar (parquet) files.

Quite neat!

Nonetheless there's an attempt to rewrite it in Rust.

As usual it's not guaranteed that it would actually be better than SQLite. C is much worse language but if you compare amount of effort that went into SQLite and compare it to a new project that's only a few months old… I wouldn't try to build anything on top of it just yet… but would keep an eye on their progress.

4 Likes

If somebody expect friendly support from redb maintainer,
just think about that twice.

Found PoloDB - not SQL, not key/value but looks pretty useful and clear in examples. It also supports transactions, not sure about multi-thread context, so let's maybe try.

UPD. seems it requires librocksdb dependency, that means not 'native' solution (#195)

Compiling polodb-librocksdb-sys v9.0.0-alpha.1
error: failed to run custom build command for `polodb-librocksdb-sys v9.0.0-alpha.1`

UPD 2. not sure yet, but surrealdb project looks interesting also

UPD 3. RustDB as maybe attempt

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.