Expand description
§wabot-feature-sqlite
SQLite foundation — the counterpart to wabot-feature-pg for a
deployment with no database server.
SqliteConfig/SqliteDatabase— one writer, a small reader pool, WAL, and pragmas chosen for low resident memory.SqliteJsonbStore— the same document shape the Postgres store uses (id/created_at/data+ promoted columns), created on first use, implementingCrudRepository.MigrationRunner— ordered, checksummed SQL migrations for the tables an application owns.
let db = SqliteDatabase::open(SqliteConfig::at("/var/lib/app/app.db"))?;
db.ping().await?;
c.register_instance::<SqliteDatabase>(Arc::new(db.clone()));
let orders: Arc<dyn CrudRepository<OrderData>> =
Arc::new(SqliteJsonbStore::new(db, "orders"));§What this is for
One node, one process, no server to operate. That is a real
deployment target — a self-hosted control plane, an appliance, an
edge box — and until now the framework had nothing for it: pg was
the only backend, so “runs on a VM with 2 GB of RAM” meant running
Postgres next to the thing that needed it.
It is also what lets a test exercise the real storage path.
InMemoryRepository proves a service compiles against the traits;
it cannot catch a query the SQL builder renders wrongly. An
in-memory SQLite database can, in the same milliseconds.
§What it is not
Not a drop-in replacement for pg at scale. There is one writer,
by construction (see database), and no distributed
Locker — a second process writing the
same file is not a supported configuration, and
InProcessLocker
is the correct choice on one node. If you need two nodes, you need
Postgres, and the repository traits are what make that a
configuration change rather than a rewrite.
Re-exports§
pub use config::SqliteConfig;pub use database::SqliteDatabase;pub use error::SqliteError;pub use error::SqliteResult;pub use jsonb::to_sql_value;pub use jsonb::PromotedColumn;pub use jsonb::SqliteJsonbStore;pub use migrations::Migration;pub use migrations::MigrationRunner;pub use migrations::MigrationStatus;pub use query_sql::build_query_sql;pub use query_sql::BuiltQuery;pub use query_sql::FieldPlacement;pub use query_sql::QuerySqlError;pub use rusqlite;
Modules§
- config
- Where the database lives and how it is tuned.
- database
- Connections: one writer, a few readers, all reached from async
code through
spawn_blocking. - error
- Error type shared by the sqlite feature and its addons.
- jsonb
SqliteJsonbStore— document storage for entities, in the same shapePgJsonbStoreuses.- migrations
- Ordered, checksummed migrations for the tables an application owns.
- query_
sql - Turning a
Queryinto SQLite SQL. - repository
SqliteJsonbStoreas aCrudRepository.