Skip to main content

toolu_orm_core/row/
mod.rs

1//! Row decoding (`FromRow`) and Postgres helpers.
2
3#[cfg(feature = "postgres")]
4mod decode_postgres;
5#[cfg(feature = "postgres")]
6mod pg_count_scalar;
7mod traits;
8
9#[cfg(feature = "postgres")]
10pub use decode_postgres::from_postgres_row;
11#[cfg(feature = "postgres")]
12pub use pg_count_scalar::PgCountScalar;
13pub use traits::FromRow;
14
15/// Generates feature-gated `FromRow` impls for a type across backend combinations.
16///
17/// Supports single-backend (one `from_row`), dual-backend, and triple-backend shapes.
18#[macro_export]
19macro_rules! impl_from_row_for {
20  (single $cfg:meta, $ty:ty, $cols:expr, $method:ident, $row_ty:ty, $body:expr) => {
21    #[$cfg]
22    impl $crate::row::FromRow for $ty {
23      const REQUIRED_COLUMNS: &'static [&'static str] = $cols;
24      fn $method(row: &$row_ty) -> Result<Self, $crate::error::DbCoreError> {
25        $body(row)
26      }
27    }
28  };
29  (dual $cfg:meta, $ty:ty, $cols:expr,
30    [$m1:ident $r1:ty => $b1:expr],
31    [$m2:ident $r2:ty => $b2:expr]
32  ) => {
33    #[$cfg]
34    impl $crate::row::FromRow for $ty {
35      const REQUIRED_COLUMNS: &'static [&'static str] = $cols;
36      fn $m1(row: &$r1) -> Result<Self, $crate::error::DbCoreError> {
37        $b1(row)
38      }
39      fn $m2(row: &$r2) -> Result<Self, $crate::error::DbCoreError> {
40        $b2(row)
41      }
42    }
43  };
44  (triple $cfg:meta, $ty:ty, $cols:expr,
45    [$m1:ident $r1:ty => $b1:expr],
46    [$m2:ident $r2:ty => $b2:expr],
47    [$m3:ident $r3:ty => $b3:expr]
48  ) => {
49    #[$cfg]
50    impl $crate::row::FromRow for $ty {
51      const REQUIRED_COLUMNS: &'static [&'static str] = $cols;
52      fn $m1(row: &$r1) -> Result<Self, $crate::error::DbCoreError> {
53        $b1(row)
54      }
55      fn $m2(row: &$r2) -> Result<Self, $crate::error::DbCoreError> {
56        $b2(row)
57      }
58      fn $m3(row: &$r3) -> Result<Self, $crate::error::DbCoreError> {
59        $b3(row)
60      }
61    }
62  };
63}