macro_rules! orm_table {
(
$(#[$table_meta:meta])*
$visibility:vis struct $table:ident => $table_name:literal {
$(
$(#[$column_meta:meta])*
$column:ident : $value:ty => $column_name:literal
),* $(,)?
}
) => { ... };
}Expand description
Define a typed table marker and its columns.
use a3s_orm::orm_table;
orm_table! {
pub struct Person => "person" {
id: i64 => "id",
name: String => "name",
}
}Column values are checked against the schema type:
ⓘ
use a3s_orm::{insert_into, orm_table};
orm_table! {
struct Person => "person" {
age: i32 => "age",
}
}
let _ = insert_into::<Person>().value(Person::age(), "not an integer");Assignments cannot use a column owned by another table:
ⓘ
use a3s_orm::{orm_table, update_table};
orm_table! { struct Person => "person" { name: String => "name" } }
orm_table! { struct Pet => "pet" { name: String => "name" } }
let _ = update_table::<Person>().set(Pet::name(), "wrong table");Expression assignments preserve the column’s declared value family:
ⓘ
use a3s_orm::{bound, orm_table, update_table};
orm_table! { struct Person => "person" { age: i32 => "age" } }
let _ = update_table::<Person>()
.set_expression(Person::age(), bound::<String>("wrong type"));Column comparisons preserve the declared SQL value family, including nullable and non-nullable forms of the same base type:
ⓘ
use a3s_orm::orm_table;
orm_table! { struct Person => "person" { id: i64 => "id" } }
orm_table! { struct Pet => "pet" { name: String => "name" } }
let _ = Person::id().eq_column(Pet::name());