pub trait Table:
Sized
+ Send
+ DeserializeOwned {
// Required methods
fn table_name() -> &'static str;
fn primary_key_columns() -> &'static [&'static str];
fn column_names() -> &'static [&'static str];
fn insertable_columns() -> &'static [&'static str];
fn field_to_column(field: &str) -> Option<&'static str>;
fn column_to_field(column: &str) -> Option<&'static str>;
fn bind_insert(&self) -> Vec<SqlParam>;
fn bind_update(&self) -> Vec<SqlParam>;
fn bind_primary_key(&self) -> Vec<SqlParam>;
// Provided method
fn schema_name() -> &'static str { ... }
}Expand description
Trait for typed table mapping (REST-only mode, no sqlx::FromRow required).
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
The database table name (e.g. “cities”).
Sourcefn primary_key_columns() -> &'static [&'static str]
fn primary_key_columns() -> &'static [&'static str]
Primary key column names.
Sourcefn column_names() -> &'static [&'static str]
fn column_names() -> &'static [&'static str]
All column names (including primary key).
Sourcefn insertable_columns() -> &'static [&'static str]
fn insertable_columns() -> &'static [&'static str]
Columns that can be inserted (excludes auto-generated columns).
Sourcefn field_to_column(field: &str) -> Option<&'static str>
fn field_to_column(field: &str) -> Option<&'static str>
Map a Rust field name to its database column name.
Sourcefn column_to_field(column: &str) -> Option<&'static str>
fn column_to_field(column: &str) -> Option<&'static str>
Map a database column name to its Rust field name.
Sourcefn bind_insert(&self) -> Vec<SqlParam>
fn bind_insert(&self) -> Vec<SqlParam>
Extract insert values as SqlParam in the order of insertable_columns().
Sourcefn bind_update(&self) -> Vec<SqlParam>
fn bind_update(&self) -> Vec<SqlParam>
Extract all non-primary-key values as SqlParam for UPDATE SET clauses.
Sourcefn bind_primary_key(&self) -> Vec<SqlParam>
fn bind_primary_key(&self) -> Vec<SqlParam>
Extract primary key values as SqlParam.
Provided Methods§
Sourcefn schema_name() -> &'static str
fn schema_name() -> &'static str
The schema name (defaults to “public”).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.