pub trait Model: Sized + Clone {
type Id: ?Sized + PartialEq + Debug + ToOwned;
// Required methods
fn all(conn: &mut SqliteConnection) -> QueryResult<Vec<Self>>;
fn find(
conn: &mut SqliteConnection,
id: &Self::Id,
) -> QueryResult<Option<Self>>;
fn id_exists(
conn: &mut SqliteConnection,
id: &Self::Id,
) -> QueryResult<bool>;
}Expand description
A trait representing a generic model with basic database operations.
This trait defines the structure for models that can be queried from a database. It includes methods for retrieving all records, finding a specific record by its ID, and checking if a record with a given ID exists.
§Type Parameters
Id: The type of the ID of the model. Must implementPartialEqandDebug.
§Methods
all: Queries all records in the database table.find: Queries a record by its primary key.id_exists: Checks if a record with the given primary key exists in the database table.
Required Associated Types§
Required Methods§
Sourcefn all(conn: &mut SqliteConnection) -> QueryResult<Vec<Self>>
fn all(conn: &mut SqliteConnection) -> QueryResult<Vec<Self>>
Sourcefn find(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<Option<Self>>
fn find(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<Option<Self>>
Sourcefn id_exists(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<bool>
fn id_exists(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<bool>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".