Skip to content

Implement SQLite database support #4785

Closed

Description

@marcelomendoncasoares

The main purpose of #4748 was to allow an easy addition of new database engines - with the most demanded being SQLite. As the database is already abstracted behind interfaces, it is only required to add a new DatabaseDialect entry and then implement the highlighted interfaces.

Pool manager

For the interaction with SQLite, we can use the battle-tested sqlite_async package that already does all the heavy-lifting on the database management level. If query introspection is needed, the sqlparser package is also worth using - both a remarkable work from Simon Binder with SQLite3 support on Dart/Flutter.

Restrictions

We should aim to support all column types on SQLite, even when advanced query operation might not be available - like with Vector columns. This will provide a predictable experience for users, specially considering the objective of using SQLite for offline-first support. It is acceptable for operations that are not supported to throw in runtime - such as trying to filter a Vector column based on the distance.

For indexes, on the other hand, we should forbid the usage of any other type than btree - the only one supported by SQLite. Otherwise it would be impossible for the analyzer to correctly match expected indexes. This is easy to implement because the config object has access to the databaseDialect while evaluating restrictions.

Migrations

Since SQLite3 has only few basic columns types available, the implementation must have special care to ensure that migrations take into consideration the model type changes and not only the column type. Otherwise, a field type change that is stored using the same database type would not be migrated and would produce deserialization issues in runtime. The premise is to preserve the type-safety of the models, and not the column types only.

Query builder

Given that "SQLite implementation strives to be compatible with PostgreSQL" [1] [2], we might be able to vastly reuse the Postgres SQL query builder. Most of the syntax we use is valid SQLite syntax, with only a few exceptions that can be worked around (like the writable CTEs when mixing rows without and with ID). The work on #4764 was already a preparation for this.

Testing

The most important part of this work is ensuring a proper test of the implementation that matches the robustness of the test suite for Postgres. One good strategy to ensure coverage is to create a new serverpod_test_sqlite project that copies all integration and migration tests from the serverpod_test_server that are related to the database.

The ideal would be to create database engine contract tests that can be blindly applied to all implementations, but this might complicate the work considerably since each dialect have different particularities and restrictions that are hard to generalize.

It is recommended that the test project is created first and adapted as needed to ensure that no critical test cases are missed during the implementation.

Additional context

When closing this issue, the following should also be closed:

Activity

  1. added
    area: database
    on Mar 3, 2026
  2. moved this from Inbox 📫 to Contributor In Progress 👩‍💻 in Serverpod Frameworkson Mar 5, 2026
  3. boshoffwillem commented on Mar 13, 2026

    @boshoffwillem

    Would you be aiming to add support for libsql? That would enable us to use remote/cloud SQLite providers like Turso. There is a flutter package (https://pub.dev/packages/libsql_dart) I have already used in a flutter app that works really well. Perhaps you can just build on this...

  4. marcelomendoncasoares commented on Mar 17, 2026

    @marcelomendoncasoares
    CollaboratorAuthor

    Would you be aiming to add support for libsql? That would enable us to use remote/cloud SQLite providers like Turso. There is a flutter package (https://pub.dev/packages/libsql_dart) I have already used in a flutter app that works really well. Perhaps you can just build on this...

    It will be possible to add in the future, but the first implementation will use sqlite_async since: (1) SQLite3 is the industry standard; (2) it has a robust community and (3) abstracts a lot of the effort in managing/interacting with the database in a way that is similar to how Serverpod connects with Postgres.

    If you want only offline + sync, you might be able to use Turso's libsql right from the beginning using the sqlite3 trick to replace the sqlite3.so, but it would be very limited in features compared to libsql_dart.

  5. moved this from Contributor In Progress 👩‍💻 to Done 🚀 in Serverpod Frameworkson Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: databaseenhancement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions