feat: add SQLite support behind a sqlite Cargo feature

Adds a SqliteDialect alongside PostgresDialect, gated by mutually exclusive
postgres (default) / sqlite Cargo features, plus a feature-selected
ActiveDatabase type alias used throughout the public Georm/Defaultable
traits. Basic CRUD and Defaultable are fully covered by a new SQLite test
suite (tests/sqlite/*) running against a real SQLite database, alongside
split migrations/sqlite/*.

Two real dialect differences surfaced beyond placeholder syntax:
- SQLite's INTEGER columns type-infer as i64 in sqlx's compile-time query
  macros (unlike Postgres SERIAL -> i32), so the SQLite test models use i64
  for integer PK/FK fields.
- sqlx's SQLite query macros need bind arguments bound to a place rather
  than passed as an inline expression (fixed once, centrally, in
  SqlDialect::generate_relation_lookup).

Composite-key entities with chrono::DateTime columns (tests/composite_key.rs)
are not yet ported to SQLite: SQLite has no TIMESTAMPTZ equivalent, so sqlx
infers TEXT date/time columns as String rather than DateTime<Utc> unless the
query explicitly overrides the column type. That needs per-field type
overrides threaded through the generated queries, left as follow-up.

CI now matrixes over both backends; formatting/audit only run once since
they don't vary by backend. examples/postgres/* stays out of
--no-default-features builds by scoping sqlite lint/test just recipes to
`-p georm` (it depends on georm's default postgres feature via Cargo
feature unification, so building it under --features sqlite at the
workspace level double-activates both dialects).
This commit is contained in:
Claude
2026-07-21 19:06:35 +00:00
parent 0d43a3fe13
commit 4c314c2f0b
31 changed files with 802 additions and 35 deletions
+3 -3
View File
@@ -7,7 +7,7 @@
<h1 align="center">Georm</h1>
<div align="center">
<strong>
A simple, type-safe SQLx ORM for PostgreSQL
A simple, type-safe SQLx ORM for PostgreSQL and SQLite
</strong>
</div>
<br/>
@@ -606,7 +606,7 @@ Georm is designed for zero runtime overhead:
- **Compile-time queries**: All SQL is verified at compile time
- **No reflection**: Direct field access, no runtime introspection
- **Minimal allocations**: Efficient use of owned vs borrowed data
- **SQLx integration**: Leverages SQLx's optimized PostgreSQL driver
- **SQLx integration**: Leverages SQLx's optimized PostgreSQL or SQLite driver, selected via the `postgres`/`sqlite` Cargo features
## Examples
@@ -651,7 +651,7 @@ cargo run help # For a list of all available actions
### High Priority
- **Simplified Relationship Syntax**: Remove redundant table/remote_id specifications by inferring them from target entity metadata
- **Multi-Database Support**: MySQL and SQLite support with feature flags
- **Multi-Database Support**: SQLite support landed behind the `sqlite` feature flag (composite keys with `chrono` columns still pending); MySQL remains unstarted
### Medium Priority
- **Composite Key Relationships**: Add relationship support (one-to-one, one-to-many, many-to-many) for entities with composite primary keys