Skip to main content

Table

Trait Table 

Source
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§

Source

fn table_name() -> &'static str

The database table name (e.g. “cities”).

Source

fn primary_key_columns() -> &'static [&'static str]

Primary key column names.

Source

fn column_names() -> &'static [&'static str]

All column names (including primary key).

Source

fn insertable_columns() -> &'static [&'static str]

Columns that can be inserted (excludes auto-generated columns).

Source

fn field_to_column(field: &str) -> Option<&'static str>

Map a Rust field name to its database column name.

Source

fn column_to_field(column: &str) -> Option<&'static str>

Map a database column name to its Rust field name.

Source

fn bind_insert(&self) -> Vec<SqlParam>

Extract insert values as SqlParam in the order of insertable_columns().

Source

fn bind_update(&self) -> Vec<SqlParam>

Extract all non-primary-key values as SqlParam for UPDATE SET clauses.

Source

fn bind_primary_key(&self) -> Vec<SqlParam>

Extract primary key values as SqlParam.

Provided Methods§

Source

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.

Implementors§