pub trait DataObjectOpsSync<T>where
T: DataObject,{
// Provided methods
fn get(conn: &impl ConnectionMethods, id: impl ToSql) -> Result<Self, Error>
where Self: Sized + DataObject,
Self::PKType: Sync { ... }
fn try_get(
conn: &impl ConnectionMethods,
id: impl ToSql,
) -> Result<Option<Self>, Error>
where Self: Sized + DataObject { ... }
fn save(&mut self, conn: &impl ConnectionMethods) -> Result<(), Error>
where Self: DataObject { ... }
fn delete(&self, conn: &impl ConnectionMethods) -> Result<(), Error>
where Self: DataObject { ... }
}Expand description
DataObject operations that require a live database connection.
Provided Methods§
Sourcefn get(conn: &impl ConnectionMethods, id: impl ToSql) -> Result<Self, Error>
fn get(conn: &impl ConnectionMethods, id: impl ToSql) -> Result<Self, Error>
Find this object in the database based on primary key.
Returns Error::NoSuchObject if the primary key does not exist.
Sourcefn try_get(
conn: &impl ConnectionMethods,
id: impl ToSql,
) -> Result<Option<Self>, Error>where
Self: Sized + DataObject,
fn try_get(
conn: &impl ConnectionMethods,
id: impl ToSql,
) -> Result<Option<Self>, Error>where
Self: Sized + DataObject,
Find this object in the database based on primary key.
Returns None if the primary key does not exist.
Sourcefn save(&mut self, conn: &impl ConnectionMethods) -> Result<(), Error>where
Self: DataObject,
fn save(&mut self, conn: &impl ConnectionMethods) -> Result<(), Error>where
Self: DataObject,
Save the object to the database, handling both inserts and updates.
If the object has an AutoPk that is uninitialized, save will always perform an insert. If the AutoPk is initialized or there is no AutoPk, save will perform an upsert (insert or replace). After saving the main object, many-to-many relationships it holds are also saved.
Sourcefn delete(&self, conn: &impl ConnectionMethods) -> Result<(), Error>where
Self: DataObject,
fn delete(&self, conn: &impl ConnectionMethods) -> Result<(), Error>where
Self: DataObject,
Delete the object from the database.