zino_orm

Trait Schema

Source
pub trait Schema:
    'static
    + Send
    + Sync
    + ModelHooks {
    type PrimaryKey: Default + Display + PartialEq;

    const PRIMARY_KEY_NAME: &'static str = "id";
    const READER_NAME: &'static str = "main";
    const WRITER_NAME: &'static str = "main";
    const TABLE_NAME: Option<&'static str> = None;
Show 77 methods // Required methods fn primary_key(&self) -> &Self::PrimaryKey; fn schema() -> &'static Schema; fn columns() -> &'static [Column<'static>]; fn fields() -> &'static [&'static str]; fn read_only_fields() -> &'static [&'static str]; fn write_only_fields() -> &'static [&'static str]; async fn acquire_reader() -> Result<&'static ConnectionPool, Error>; async fn acquire_writer() -> Result<&'static ConnectionPool, Error>; // Provided methods fn driver_name() -> &'static str { ... } fn table_prefix() -> &'static str { ... } fn namespace_prefix() -> &'static str { ... } fn table_name() -> &'static str { ... } fn model_namespace() -> &'static str { ... } fn primary_key_value(&self) -> JsonValue { ... } fn primary_key_column() -> &'static Column<'static> { ... } fn get_column(key: &str) -> Option<&Column<'static>> { ... } fn get_writable_column(key: &str) -> Option<&Column<'static>> { ... } fn has_column(key: &str) -> bool { ... } fn default_query() -> Query { ... } fn default_mutation() -> Mutation { ... } fn init_reader() -> Result<&'static ConnectionPool, Error> { ... } fn init_writer() -> Result<&'static ConnectionPool, Error> { ... } async fn create_table() -> Result<(), Error> { ... } async fn synchronize_schema() -> Result<(), Error> { ... } async fn create_indexes() -> Result<u64, Error> { ... } async fn prepare_insert(self) -> Result<QueryContext, Error> { ... } async fn insert(self) -> Result<QueryContext, Error> { ... } async fn prepare_insert_many( models: Vec<Self>, ) -> Result<QueryContext, Error> { ... } async fn insert_many(models: Vec<Self>) -> Result<QueryContext, Error> { ... } async fn prepare_insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error> where C: AsRef<str>, E: Entity + Schema { ... } async fn insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error> where C: AsRef<str>, E: Entity + Schema { ... } async fn prepare_update(self) -> Result<QueryContext, Error> { ... } async fn update(self) -> Result<QueryContext, Error> { ... } async fn prepare_update_partial<C: AsRef<str>>( self, columns: &[C], ) -> Result<QueryContext, Error> { ... } async fn update_partial<C: AsRef<str>>( self, columns: &[C], ) -> Result<QueryContext, Error> { ... } async fn prepare_update_one( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error> { ... } async fn update_one( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error> { ... } async fn prepare_update_many( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error> { ... } async fn update_many( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error> { ... } async fn prepare_upsert(self) -> Result<QueryContext, Error> { ... } async fn upsert(self) -> Result<QueryContext, Error> { ... } async fn prepare_delete() -> Result<QueryContext, Error> { ... } async fn delete(self) -> Result<QueryContext, Error> { ... } async fn prepare_delete_one(query: &Query) -> Result<QueryContext, Error> { ... } async fn delete_one(query: &Query) -> Result<QueryContext, Error> { ... } async fn prepare_delete_many(query: &Query) -> Result<QueryContext, Error> { ... } async fn delete_many(query: &Query) -> Result<QueryContext, Error> { ... } async fn prepare_delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error> where C: AsRef<str>, E: Entity + Schema { ... } async fn delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error> where C: AsRef<str>, E: Entity + Schema { ... } async fn find<T>(query: &Query) -> Result<Vec<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn find_as<T: DeserializeOwned>( query: &Query, ) -> Result<Vec<T>, Error> { ... } async fn find_one<T>(query: &Query) -> Result<Option<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn find_one_as<T: DeserializeOwned>( query: &Query, ) -> Result<Option<T>, Error> { ... } async fn populate<C: AsRef<str>>( query: &mut Query, data: &mut Vec<Map>, columns: &[C], ) -> Result<u64, Error> { ... } async fn populate_one<C: AsRef<str>>( query: &mut Query, data: &mut Map, columns: &[C], ) -> Result<(), Error> { ... } async fn lookup<M, T>( query: &Query, join_on: &JoinOn<Self, M>, ) -> Result<Vec<T>, Error> where M: Schema, T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn lookup_as<M, T>( query: &Query, join_on: &JoinOn<Self, M>, ) -> Result<Vec<T>, Error> where M: Schema, T: DeserializeOwned { ... } async fn exists(query: &Query) -> Result<bool, Error> { ... } async fn count(query: &Query) -> Result<u64, Error> { ... } async fn count_many<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, Error> where C: AsRef<str>, T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn count_many_as<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, Error> where C: AsRef<str>, T: DeserializeOwned { ... } async fn aggregate<T>(query: &Query) -> Result<Vec<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn aggregate_as<T: DeserializeOwned>( query: &Query, ) -> Result<Vec<T>, Error> { ... } async fn execute( query: &str, params: Option<&Map>, ) -> Result<QueryContext, Error> { ... } async fn query<T>( query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn query_as<T: DeserializeOwned>( query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error> { ... } async fn query_one<T>( query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn query_one_as<T: DeserializeOwned>( query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error> { ... } async fn prepare_delete_by_id() -> Result<QueryContext, Error> { ... } async fn delete_by_id( primary_key: &Self::PrimaryKey, ) -> Result<QueryContext, Error> { ... } async fn prepare_update_by_id( mutation: &mut Mutation, ) -> Result<QueryContext, Error> { ... } async fn update_by_id<T>( primary_key: &Self::PrimaryKey, mutation: &mut Mutation, ) -> Result<Option<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn find_by_id<T>( primary_key: &Self::PrimaryKey, ) -> Result<Option<T>, Error> where T: DecodeRow<DatabaseRow, Error = Error> { ... } async fn try_get_model( primary_key: &Self::PrimaryKey, ) -> Result<Self, Error> { ... } async fn sample(size: usize) -> Result<Vec<JsonValue>, Error> { ... } async fn filter<T: IntoSqlValue>( primary_key_values: Vec<T>, ) -> Result<Vec<JsonValue>, Error> { ... } async fn is_unique_on<C, T>( &self, columns: Vec<(C, T)>, ) -> Result<bool, Error> where C: AsRef<str>, T: IntoSqlValue { ... }
}
Expand description

Database schema.

This trait can be derived by zino_derive::Schema.

Provided Associated Constants§

Source

const PRIMARY_KEY_NAME: &'static str = "id"

Primary key name.

Source

const READER_NAME: &'static str = "main"

Reader name.

Source

const WRITER_NAME: &'static str = "main"

Writer name.

Source

const TABLE_NAME: Option<&'static str> = None

Optional custom table name.

Required Associated Types§

Source

type PrimaryKey: Default + Display + PartialEq

Primary key.

Required Methods§

Source

fn primary_key(&self) -> &Self::PrimaryKey

Returns the primary key.

Source

fn schema() -> &'static Schema

Returns a reference to the Avro schema.

Source

fn columns() -> &'static [Column<'static>]

Returns a reference to the columns.

Source

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

Returns a reference to the column fields.

Source

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

Returns a reference to the read-only column fields.

Source

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

Returns a reference to the write-only column fields.

Source

async fn acquire_reader() -> Result<&'static ConnectionPool, Error>

Retrieves a connection pool for the model reader.

Source

async fn acquire_writer() -> Result<&'static ConnectionPool, Error>

Retrieves a connection pool for the model writer.

Provided Methods§

Source

fn driver_name() -> &'static str

Returns the driver name.

Supported drivers: mariadb | mysql | postgres | sqlite | tidb.

Source

fn table_prefix() -> &'static str

Returns the prefix for the table name.

Source

fn namespace_prefix() -> &'static str

Returns the prefix for the model namespace.

Source

fn table_name() -> &'static str

Returns the table name.

Source

fn model_namespace() -> &'static str

Returns the model namespace.

Source

fn primary_key_value(&self) -> JsonValue

Returns the primary key as a JSON value.

Source

fn primary_key_column() -> &'static Column<'static>

Returns the primary key column.

Source

fn get_column(key: &str) -> Option<&Column<'static>>

Gets a column for the field.

Source

fn get_writable_column(key: &str) -> Option<&Column<'static>>

Gets a column for the field if it is writable.

Source

fn has_column(key: &str) -> bool

Returns true if the model has a column for the specific field.

Source

fn default_query() -> Query

Constructs a default Query for the model.

Source

fn default_mutation() -> Mutation

Constructs a default Mutation for the model.

Source

fn init_reader() -> Result<&'static ConnectionPool, Error>

Initializes the model reader.

Source

fn init_writer() -> Result<&'static ConnectionPool, Error>

Initializes the model writer.

Source

async fn create_table() -> Result<(), Error>

Creates a database table for the model.

Source

async fn synchronize_schema() -> Result<(), Error>

Synchronizes the table schema for the model.

Source

async fn create_indexes() -> Result<u64, Error>

Creates indexes for the model.

Source

async fn prepare_insert(self) -> Result<QueryContext, Error>

Prepares the SQL to insert the model into the table.

Source

async fn insert(self) -> Result<QueryContext, Error>

Inserts the model into the table.

Source

async fn prepare_insert_many(models: Vec<Self>) -> Result<QueryContext, Error>

Prepares the SQL to insert many models into the table.

Source

async fn insert_many(models: Vec<Self>) -> Result<QueryContext, Error>

Inserts many models into the table.

Source

async fn prepare_insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
where C: AsRef<str>, E: Entity + Schema,

Prepares the SQL to insert models selected by a subquery.

Source

async fn insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
where C: AsRef<str>, E: Entity + Schema,

Inserts the models selected by a subquery.

Source

async fn prepare_update(self) -> Result<QueryContext, Error>

Prepares the SQL to update the model in the table.

Source

async fn update(self) -> Result<QueryContext, Error>

Updates the model in the table.

Source

async fn prepare_update_partial<C: AsRef<str>>( self, columns: &[C], ) -> Result<QueryContext, Error>

Prepares the SQL to update the model for partial columns in the table.

Source

async fn update_partial<C: AsRef<str>>( self, columns: &[C], ) -> Result<QueryContext, Error>

Updates the model for partial columns in the table.

Source

async fn prepare_update_one( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>

Prepares the SQL to update at most one model selected by the query in the table.

Source

async fn update_one( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>

Updates at most one model selected by the query in the table.

Source

async fn prepare_update_many( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>

Prepares the SQL to update many models selected by the query in the table.

Source

async fn update_many( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>

Updates many models selected by the query in the table.

Source

async fn prepare_upsert(self) -> Result<QueryContext, Error>

Prepares the SQL to update or insert the model into the table.

Source

async fn upsert(self) -> Result<QueryContext, Error>

Updates or inserts the model into the table.

Source

async fn prepare_delete() -> Result<QueryContext, Error>

Prepares the SQL to delete the model in the table.

Source

async fn delete(self) -> Result<QueryContext, Error>

Deletes the model in the table.

Source

async fn prepare_delete_one(query: &Query) -> Result<QueryContext, Error>

Prepares the SQL to delete at most one model selected by the query in the table.

Source

async fn delete_one(query: &Query) -> Result<QueryContext, Error>

Deletes at most one model selected by the query in the table.

Source

async fn prepare_delete_many(query: &Query) -> Result<QueryContext, Error>

Prepares the SQL to delete many models selected by the query in the table.

Source

async fn delete_many(query: &Query) -> Result<QueryContext, Error>

Deletes many models selected by the query in the table.

Source

async fn prepare_delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
where C: AsRef<str>, E: Entity + Schema,

Prepares the SQL to delete models selected by a subquery.

Source

async fn delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
where C: AsRef<str>, E: Entity + Schema,

Deletes the models selected by a subquery.

Source

async fn find<T>(query: &Query) -> Result<Vec<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Finds a list of models selected by the query in the table, and decodes it as Vec<T>.

Source

async fn find_as<T: DeserializeOwned>(query: &Query) -> Result<Vec<T>, Error>

Finds a list of models selected by the query in the table, and parses it as Vec<T>.

Source

async fn find_one<T>(query: &Query) -> Result<Option<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Finds one model selected by the query in the table, and decodes it as an instance of type T.

Source

async fn find_one_as<T: DeserializeOwned>( query: &Query, ) -> Result<Option<T>, Error>

Finds one model selected by the query in the table, and parses it as an instance of type T.

Source

async fn populate<C: AsRef<str>>( query: &mut Query, data: &mut Vec<Map>, columns: &[C], ) -> Result<u64, Error>

Populates the related data in the corresponding columns for Vec<Map> using a merged select on the primary key, which solves the N+1 problem.

Source

async fn populate_one<C: AsRef<str>>( query: &mut Query, data: &mut Map, columns: &[C], ) -> Result<(), Error>

Populates the related data in the corresponding columns for Map using a merged select on the primary key, which solves the N+1 problem.

Source

async fn lookup<M, T>( query: &Query, join_on: &JoinOn<Self, M>, ) -> Result<Vec<T>, Error>
where M: Schema, T: DecodeRow<DatabaseRow, Error = Error>,

Performs a join to another table to filter rows in the “joined” table, and decodes it as Vec<T>.

Source

async fn lookup_as<M, T>( query: &Query, join_on: &JoinOn<Self, M>, ) -> Result<Vec<T>, Error>
where M: Schema, T: DeserializeOwned,

Performs a join to another table to filter rows in the “joined” table, and parses it as Vec<T>.

Source

async fn exists(query: &Query) -> Result<bool, Error>

Checks whether there is a model selected by the query in the table.

Source

async fn count(query: &Query) -> Result<u64, Error>

Counts the number of rows selected by the query in the table.

Source

async fn count_many<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, Error>
where C: AsRef<str>, T: DecodeRow<DatabaseRow, Error = Error>,

Counts the number of rows selected by the query in the table. The boolean value determines whether it only counts distinct values or not.

Source

async fn count_many_as<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, Error>
where C: AsRef<str>, T: DeserializeOwned,

Counts the number of rows selected by the query in the table, and parses it as an instance of type T.

Source

async fn aggregate<T>(query: &Query) -> Result<Vec<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Aggregates the rows selected by the query in the table.

Source

async fn aggregate_as<T: DeserializeOwned>( query: &Query, ) -> Result<Vec<T>, Error>

Aggregates the rows selected by the query in the table, and parses it as an instance of type T.

Source

async fn execute( query: &str, params: Option<&Map>, ) -> Result<QueryContext, Error>

Executes the query in the table, and returns the total number of rows affected.

Source

async fn query<T>(query: &str, params: Option<&Map>) -> Result<Vec<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Executes the query in the table, and decodes it as Vec<T>.

Source

async fn query_as<T: DeserializeOwned>( query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error>

Executes the query in the table, and parses it as Vec<T>.

Source

async fn query_one<T>( query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Executes the query in the table, and decodes it as an instance of type T.

Source

async fn query_one_as<T: DeserializeOwned>( query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>

Executes the query in the table, and parses it as an instance of type T.

Source

async fn prepare_delete_by_id() -> Result<QueryContext, Error>

Prepares the SQL to delete a model selected by the primary key in the table.

Source

async fn delete_by_id( primary_key: &Self::PrimaryKey, ) -> Result<QueryContext, Error>

Deletes a model selected by the primary key in the table.

Source

async fn prepare_update_by_id( mutation: &mut Mutation, ) -> Result<QueryContext, Error>

Prepares the SQL to update a model selected by the primary key in the table.

Source

async fn update_by_id<T>( primary_key: &Self::PrimaryKey, mutation: &mut Mutation, ) -> Result<Option<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Updates a model selected by the primary key in the table, and decodes it as an instance of type T.

Source

async fn find_by_id<T>( primary_key: &Self::PrimaryKey, ) -> Result<Option<T>, Error>
where T: DecodeRow<DatabaseRow, Error = Error>,

Finds a model selected by the primary key in the table, and decodes it as an instance of type T.

Source

async fn try_get_model(primary_key: &Self::PrimaryKey) -> Result<Self, Error>

Finds a model selected by the primary key in the table, and parses it as Self.

Source

async fn sample(size: usize) -> Result<Vec<JsonValue>, Error>

Randomly selects the specified number of models from the table and returns a list of the primary key values.

Source

async fn filter<T: IntoSqlValue>( primary_key_values: Vec<T>, ) -> Result<Vec<JsonValue>, Error>

Filters the values of the primary key.

Source

async fn is_unique_on<C, T>(&self, columns: Vec<(C, T)>) -> Result<bool, Error>
where C: AsRef<str>, T: IntoSqlValue,

Returns true if the model is unique on the column values.

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§