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§
Sourceconst PRIMARY_KEY_NAME: &'static str = "id"
const PRIMARY_KEY_NAME: &'static str = "id"
Primary key name.
Sourceconst READER_NAME: &'static str = "main"
const READER_NAME: &'static str = "main"
Reader name.
Sourceconst WRITER_NAME: &'static str = "main"
const WRITER_NAME: &'static str = "main"
Writer name.
Sourceconst TABLE_NAME: Option<&'static str> = None
const TABLE_NAME: Option<&'static str> = None
Optional custom table name.
Required Associated Types§
Sourcetype PrimaryKey: Default + Display + PartialEq
type PrimaryKey: Default + Display + PartialEq
Primary key.
Required Methods§
Sourcefn primary_key(&self) -> &Self::PrimaryKey
fn primary_key(&self) -> &Self::PrimaryKey
Returns the primary key.
Sourcefn read_only_fields() -> &'static [&'static str]
fn read_only_fields() -> &'static [&'static str]
Returns a reference to the read-only column fields.
Sourcefn write_only_fields() -> &'static [&'static str]
fn write_only_fields() -> &'static [&'static str]
Returns a reference to the write-only column fields.
Sourceasync fn acquire_reader() -> Result<&'static ConnectionPool, Error>
async fn acquire_reader() -> Result<&'static ConnectionPool, Error>
Retrieves a connection pool for the model reader.
Sourceasync fn acquire_writer() -> Result<&'static ConnectionPool, Error>
async fn acquire_writer() -> Result<&'static ConnectionPool, Error>
Retrieves a connection pool for the model writer.
Provided Methods§
Sourcefn driver_name() -> &'static str
fn driver_name() -> &'static str
Returns the driver name.
Supported drivers: mariadb
| mysql
| postgres
| sqlite
| tidb
.
Sourcefn table_prefix() -> &'static str
fn table_prefix() -> &'static str
Returns the prefix for the table name.
Sourcefn namespace_prefix() -> &'static str
fn namespace_prefix() -> &'static str
Returns the prefix for the model namespace.
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Returns the table name.
Sourcefn model_namespace() -> &'static str
fn model_namespace() -> &'static str
Returns the model namespace.
Sourcefn primary_key_value(&self) -> JsonValue
fn primary_key_value(&self) -> JsonValue
Returns the primary key as a JSON value.
Sourcefn primary_key_column() -> &'static Column<'static>
fn primary_key_column() -> &'static Column<'static>
Returns the primary key column.
Sourcefn get_column(key: &str) -> Option<&Column<'static>>
fn get_column(key: &str) -> Option<&Column<'static>>
Gets a column for the field.
Sourcefn get_writable_column(key: &str) -> Option<&Column<'static>>
fn get_writable_column(key: &str) -> Option<&Column<'static>>
Gets a column for the field if it is writable.
Sourcefn has_column(key: &str) -> bool
fn has_column(key: &str) -> bool
Returns true
if the model has a column for the specific field.
Sourcefn default_query() -> Query
fn default_query() -> Query
Constructs a default Query
for the model.
Sourcefn default_mutation() -> Mutation
fn default_mutation() -> Mutation
Constructs a default Mutation
for the model.
Sourcefn init_reader() -> Result<&'static ConnectionPool, Error>
fn init_reader() -> Result<&'static ConnectionPool, Error>
Initializes the model reader.
Sourcefn init_writer() -> Result<&'static ConnectionPool, Error>
fn init_writer() -> Result<&'static ConnectionPool, Error>
Initializes the model writer.
Sourceasync fn create_table() -> Result<(), Error>
async fn create_table() -> Result<(), Error>
Creates a database table for the model.
Sourceasync fn synchronize_schema() -> Result<(), Error>
async fn synchronize_schema() -> Result<(), Error>
Synchronizes the table schema for the model.
Sourceasync fn create_indexes() -> Result<u64, Error>
async fn create_indexes() -> Result<u64, Error>
Creates indexes for the model.
Sourceasync fn prepare_insert(self) -> Result<QueryContext, Error>
async fn prepare_insert(self) -> Result<QueryContext, Error>
Prepares the SQL to insert the model into the table.
Sourceasync fn insert(self) -> Result<QueryContext, Error>
async fn insert(self) -> Result<QueryContext, Error>
Inserts the model into the table.
Sourceasync fn prepare_insert_many(models: Vec<Self>) -> Result<QueryContext, Error>
async fn prepare_insert_many(models: Vec<Self>) -> Result<QueryContext, Error>
Prepares the SQL to insert many models into the table.
Sourceasync fn insert_many(models: Vec<Self>) -> Result<QueryContext, Error>
async fn insert_many(models: Vec<Self>) -> Result<QueryContext, Error>
Inserts many models into the table.
Sourceasync fn prepare_insert_from_subquery<C, E>(
columns: &[C],
subquery: QueryBuilder<E>,
) -> Result<QueryContext, Error>
async fn prepare_insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
Prepares the SQL to insert models selected by a subquery.
Sourceasync fn insert_from_subquery<C, E>(
columns: &[C],
subquery: QueryBuilder<E>,
) -> Result<QueryContext, Error>
async fn insert_from_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
Inserts the models selected by a subquery.
Sourceasync fn prepare_update(self) -> Result<QueryContext, Error>
async fn prepare_update(self) -> Result<QueryContext, Error>
Prepares the SQL to update the model in the table.
Sourceasync fn update(self) -> Result<QueryContext, Error>
async fn update(self) -> Result<QueryContext, Error>
Updates the model in the table.
Sourceasync fn prepare_update_partial<C: AsRef<str>>(
self,
columns: &[C],
) -> Result<QueryContext, Error>
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.
Sourceasync fn update_partial<C: AsRef<str>>(
self,
columns: &[C],
) -> Result<QueryContext, Error>
async fn update_partial<C: AsRef<str>>( self, columns: &[C], ) -> Result<QueryContext, Error>
Updates the model for partial columns in the table.
Sourceasync fn prepare_update_one(
query: &Query,
mutation: &mut Mutation,
) -> Result<QueryContext, Error>
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.
Sourceasync fn update_one(
query: &Query,
mutation: &mut Mutation,
) -> Result<QueryContext, Error>
async fn update_one( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>
Updates at most one model selected by the query in the table.
Sourceasync fn prepare_update_many(
query: &Query,
mutation: &mut Mutation,
) -> Result<QueryContext, Error>
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.
Sourceasync fn update_many(
query: &Query,
mutation: &mut Mutation,
) -> Result<QueryContext, Error>
async fn update_many( query: &Query, mutation: &mut Mutation, ) -> Result<QueryContext, Error>
Updates many models selected by the query in the table.
Sourceasync fn prepare_upsert(self) -> Result<QueryContext, Error>
async fn prepare_upsert(self) -> Result<QueryContext, Error>
Prepares the SQL to update or insert the model into the table.
Sourceasync fn upsert(self) -> Result<QueryContext, Error>
async fn upsert(self) -> Result<QueryContext, Error>
Updates or inserts the model into the table.
Sourceasync fn prepare_delete() -> Result<QueryContext, Error>
async fn prepare_delete() -> Result<QueryContext, Error>
Prepares the SQL to delete the model in the table.
Sourceasync fn delete(self) -> Result<QueryContext, Error>
async fn delete(self) -> Result<QueryContext, Error>
Deletes the model in the table.
Sourceasync fn prepare_delete_one(query: &Query) -> Result<QueryContext, Error>
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.
Sourceasync fn delete_one(query: &Query) -> Result<QueryContext, Error>
async fn delete_one(query: &Query) -> Result<QueryContext, Error>
Deletes at most one model selected by the query in the table.
Sourceasync fn prepare_delete_many(query: &Query) -> Result<QueryContext, Error>
async fn prepare_delete_many(query: &Query) -> Result<QueryContext, Error>
Prepares the SQL to delete many models selected by the query in the table.
Sourceasync fn delete_many(query: &Query) -> Result<QueryContext, Error>
async fn delete_many(query: &Query) -> Result<QueryContext, Error>
Deletes many models selected by the query in the table.
Sourceasync fn prepare_delete_by_subquery<C, E>(
columns: &[C],
subquery: QueryBuilder<E>,
) -> Result<QueryContext, Error>
async fn prepare_delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
Prepares the SQL to delete models selected by a subquery.
Sourceasync fn delete_by_subquery<C, E>(
columns: &[C],
subquery: QueryBuilder<E>,
) -> Result<QueryContext, Error>
async fn delete_by_subquery<C, E>( columns: &[C], subquery: QueryBuilder<E>, ) -> Result<QueryContext, Error>
Deletes the models selected by a subquery.
Sourceasync fn find<T>(query: &Query) -> Result<Vec<T>, Error>
async fn find<T>(query: &Query) -> Result<Vec<T>, Error>
Finds a list of models selected by the query in the table,
and decodes it as Vec<T>
.
Sourceasync fn find_as<T: DeserializeOwned>(query: &Query) -> Result<Vec<T>, Error>
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>
.
Sourceasync fn find_one<T>(query: &Query) -> Result<Option<T>, Error>
async fn find_one<T>(query: &Query) -> Result<Option<T>, Error>
Finds one model selected by the query in the table,
and decodes it as an instance of type T
.
Sourceasync fn find_one_as<T: DeserializeOwned>(
query: &Query,
) -> Result<Option<T>, Error>
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
.
Sourceasync fn populate<C: AsRef<str>>(
query: &mut Query,
data: &mut Vec<Map>,
columns: &[C],
) -> Result<u64, Error>
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.
Sourceasync fn populate_one<C: AsRef<str>>(
query: &mut Query,
data: &mut Map,
columns: &[C],
) -> Result<(), Error>
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.
Sourceasync fn lookup<M, T>(
query: &Query,
join_on: &JoinOn<Self, M>,
) -> Result<Vec<T>, Error>
async fn lookup<M, T>( query: &Query, join_on: &JoinOn<Self, M>, ) -> Result<Vec<T>, Error>
Performs a join to another table to filter rows in the “joined” table,
and decodes it as Vec<T>
.
Sourceasync fn lookup_as<M, T>(
query: &Query,
join_on: &JoinOn<Self, M>,
) -> Result<Vec<T>, Error>where
M: Schema,
T: DeserializeOwned,
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>
.
Sourceasync fn exists(query: &Query) -> Result<bool, Error>
async fn exists(query: &Query) -> Result<bool, Error>
Checks whether there is a model selected by the query in the table.
Sourceasync fn count(query: &Query) -> Result<u64, Error>
async fn count(query: &Query) -> Result<u64, Error>
Counts the number of rows selected by the query in the table.
Sourceasync fn count_many<C, T>(
query: &Query,
columns: &[(C, bool)],
) -> Result<T, Error>
async fn count_many<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, 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.
Sourceasync fn count_many_as<C, T>(
query: &Query,
columns: &[(C, bool)],
) -> Result<T, Error>
async fn count_many_as<C, T>( query: &Query, columns: &[(C, bool)], ) -> Result<T, Error>
Counts the number of rows selected by the query in the table,
and parses it as an instance of type T
.
Sourceasync fn aggregate<T>(query: &Query) -> Result<Vec<T>, Error>
async fn aggregate<T>(query: &Query) -> Result<Vec<T>, Error>
Aggregates the rows selected by the query in the table.
Sourceasync fn aggregate_as<T: DeserializeOwned>(
query: &Query,
) -> Result<Vec<T>, Error>
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
.
Sourceasync fn execute(
query: &str,
params: Option<&Map>,
) -> Result<QueryContext, Error>
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.
Sourceasync fn query<T>(query: &str, params: Option<&Map>) -> Result<Vec<T>, Error>
async fn query<T>(query: &str, params: Option<&Map>) -> Result<Vec<T>, Error>
Executes the query in the table, and decodes it as Vec<T>
.
Sourceasync fn query_as<T: DeserializeOwned>(
query: &str,
params: Option<&Map>,
) -> Result<Vec<T>, Error>
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>
.
Sourceasync fn query_one<T>(
query: &str,
params: Option<&Map>,
) -> Result<Option<T>, Error>
async fn query_one<T>( query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
Executes the query in the table, and decodes it as an instance of type T
.
Sourceasync fn query_one_as<T: DeserializeOwned>(
query: &str,
params: Option<&Map>,
) -> Result<Option<T>, Error>
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
.
Sourceasync fn prepare_delete_by_id() -> Result<QueryContext, Error>
async fn prepare_delete_by_id() -> Result<QueryContext, Error>
Prepares the SQL to delete a model selected by the primary key in the table.
Sourceasync fn delete_by_id(
primary_key: &Self::PrimaryKey,
) -> Result<QueryContext, Error>
async fn delete_by_id( primary_key: &Self::PrimaryKey, ) -> Result<QueryContext, Error>
Deletes a model selected by the primary key in the table.
Sourceasync fn prepare_update_by_id(
mutation: &mut Mutation,
) -> Result<QueryContext, Error>
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.
Sourceasync fn update_by_id<T>(
primary_key: &Self::PrimaryKey,
mutation: &mut Mutation,
) -> Result<Option<T>, Error>
async fn update_by_id<T>( primary_key: &Self::PrimaryKey, mutation: &mut Mutation, ) -> Result<Option<T>, Error>
Updates a model selected by the primary key in the table,
and decodes it as an instance of type T
.
Sourceasync fn find_by_id<T>(
primary_key: &Self::PrimaryKey,
) -> Result<Option<T>, Error>
async fn find_by_id<T>( primary_key: &Self::PrimaryKey, ) -> Result<Option<T>, Error>
Finds a model selected by the primary key in the table,
and decodes it as an instance of type T
.
Sourceasync fn try_get_model(primary_key: &Self::PrimaryKey) -> Result<Self, Error>
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
.
Sourceasync fn sample(size: usize) -> Result<Vec<JsonValue>, Error>
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.
Sourceasync fn filter<T: IntoSqlValue>(
primary_key_values: Vec<T>,
) -> Result<Vec<JsonValue>, Error>
async fn filter<T: IntoSqlValue>( primary_key_values: Vec<T>, ) -> Result<Vec<JsonValue>, Error>
Filters the values of the primary key.
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.