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

SQLite is still the best solution.

8 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.

7 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

6 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.