Skip to main content

floz_orm/db/
row_bound.rs

1//! `FlozRowBound` — cfg-gated trait alias for `sqlx::FromRow` bounds.
2//!
3//! This marker trait adapts to enabled database features:
4//! - `postgres` only → requires `FromRow<PgRow>`
5//! - `sqlite` only → requires `FromRow<SqliteRow>`
6//! - both → requires both
7//!
8//! Since `#[derive(sqlx::FromRow)]` generates a generic impl over all
9//! row types, any `schema!` model automatically satisfies `FlozRowBound`.
10
11#[cfg(feature = "postgres")]
12use sqlx::postgres::PgRow;
13#[cfg(feature = "sqlite")]
14use sqlx::sqlite::SqliteRow;
15
16// ── Postgres only ──
17
18#[cfg(all(feature = "postgres", not(feature = "sqlite")))]
19pub trait FlozRowBound: for<'r> sqlx::FromRow<'r, PgRow> {}
20
21#[cfg(all(feature = "postgres", not(feature = "sqlite")))]
22impl<T> FlozRowBound for T where T: for<'r> sqlx::FromRow<'r, PgRow> {}
23
24// ── SQLite only ──
25
26#[cfg(all(feature = "sqlite", not(feature = "postgres")))]
27pub trait FlozRowBound: for<'r> sqlx::FromRow<'r, SqliteRow> {}
28
29#[cfg(all(feature = "sqlite", not(feature = "postgres")))]
30impl<T> FlozRowBound for T where T: for<'r> sqlx::FromRow<'r, SqliteRow> {}
31
32// ── Both enabled ──
33
34#[cfg(all(feature = "postgres", feature = "sqlite"))]
35pub trait FlozRowBound:
36    for<'r> sqlx::FromRow<'r, PgRow> + for<'r> sqlx::FromRow<'r, SqliteRow>
37{
38}
39
40#[cfg(all(feature = "postgres", feature = "sqlite"))]
41impl<T> FlozRowBound for T where
42    T: for<'r> sqlx::FromRow<'r, PgRow> + for<'r> sqlx::FromRow<'r, SqliteRow>
43{
44}
45
46// ── No database features ──
47
48#[cfg(not(any(feature = "postgres", feature = "sqlite")))]
49pub trait FlozRowBound {}
50
51#[cfg(not(any(feature = "postgres", feature = "sqlite")))]
52impl<T> FlozRowBound for T {}