DataObjectOpsSync

Trait DataObjectOpsSync 

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

Source

fn get(conn: &impl ConnectionMethods, id: impl ToSql) -> Result<Self, Error>
where Self: Sized + DataObject, Self::PKType: Sync,

Find this object in the database based on primary key. Returns Error::NoSuchObject if the primary key does not exist.

Source

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.

Source

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.

Source

fn delete(&self, conn: &impl ConnectionMethods) -> Result<(), Error>
where Self: DataObject,

Delete the object from the database.

Implementors§

Source§

impl<T> DataObjectOpsSync<T> for T
where T: DataObject,