mirror of
https://github.com/Phundrak/georm.git
synced 2026-07-28 20:09:18 +02:00
4c314c2f0b
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).
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
#![cfg(feature = "sqlite")]
|
|
|
|
use georm::Georm;
|
|
|
|
#[derive(Debug, Georm, PartialEq, Eq, Default)]
|
|
#[georm(
|
|
table = "biographies",
|
|
one_to_one = [{
|
|
name = "author", remote_id = "biography_id", table = "authors", entity = Author
|
|
}]
|
|
)]
|
|
pub struct Biography {
|
|
#[georm(id)]
|
|
pub id: i64,
|
|
pub content: String,
|
|
}
|
|
|
|
#[derive(Debug, Georm, PartialEq, Eq, Default)]
|
|
#[georm(table = "authors")]
|
|
pub struct Author {
|
|
#[georm(id)]
|
|
pub id: i64,
|
|
pub name: String,
|
|
#[georm(relation = {entity = Biography, table = "biographies", name = "biography", nullable = true})]
|
|
pub biography_id: Option<i64>,
|
|
}
|
|
|
|
impl PartialOrd for Author {
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
Some(self.id.cmp(&other.id))
|
|
}
|
|
}
|
|
|
|
impl Ord for Author {
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
self.id.cmp(&other.id)
|
|
}
|
|
}
|
|
|
|
// UserRole (composite key, chrono::DateTime<Utc> column) is deliberately not
|
|
// ported here yet: SQLite's compile-time query macros infer TEXT columns as
|
|
// `String`, not `chrono::DateTime<Utc>` — unlike Postgres's TIMESTAMPTZ, which
|
|
// maps directly. Fixing this needs per-column `query_as!` type overrides
|
|
// (`"assigned_at as \"assigned_at: DateTime<Utc>\""`) threaded through the
|
|
// dialect's generated queries, which is follow-up work, not part of this
|
|
// first SQLite slice. See tests/sqlite/composite_key.rs (not yet added).
|