Skip to main content

Persistence

Trait Persistence 

Source
pub trait Persistence: AsyncPersistence {
    // Provided methods
    fn save_sync(&mut self) -> Result<(), RecordError>
       where Self: Serialize,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn save_bang_sync(&mut self) -> Result<(), RecordError>
       where Self: Serialize,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn create_sync(attrs: HashMap<String, Value>) -> Result<Self, RecordError>
       where Self: Default + Serialize + DeserializeOwned,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn insert_all_sync(
        records: Vec<HashMap<String, Value>>,
    ) -> Result<Vec<Self>, RecordError>
       where Self: Default + Serialize + DeserializeOwned,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn upsert_sync(
        attrs: HashMap<String, Value>,
        unique_by: &[&str],
    ) -> Result<Self, RecordError>
       where Self: Default + Serialize + DeserializeOwned,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn upsert_all_sync(
        records: Vec<HashMap<String, Value>>,
        unique_by: &[&str],
    ) -> Result<Vec<Self>, RecordError>
       where Self: Default + Serialize + DeserializeOwned,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn update_attributes_sync(
        &mut self,
        attrs: HashMap<String, Value>,
    ) -> Result<(), RecordError>
       where Self: Serialize + DeserializeOwned,
             <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
             <Self::Entity as EntityTrait>::Model: IntoActiveModel<<Self::Entity as EntityTrait>::ActiveModel>,
             <Self::Entity as EntityTrait>::ActiveModel: ActiveModelBehavior + Send { ... }
    fn destroy_sync(&mut self) -> Result<(), RecordError>
       where <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable { ... }
    fn reload_sync(&mut self) -> Result<(), RecordError>
       where <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable { ... }
    fn delete_sync(id: i64) -> Result<(), RecordError>
       where <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable { ... }
    fn update_all_sync(
        conditions: HashMap<String, Value>,
        updates: HashMap<String, Value>,
    ) -> Result<u64, RecordError>
       where <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable { ... }
    fn destroy_all_sync(
        conditions: HashMap<String, Value>,
    ) -> Result<u64, RecordError>
       where <Self::Entity as EntityTrait>::Column: ColumnTrait + Iterable { ... }
}
Expand description

Synchronous persistence interface for [Record] types.

Provided Methods§

Source

fn save_sync(&mut self) -> Result<(), RecordError>

Saves the record, inserting or updating based on its current state.

Source

fn save_bang_sync(&mut self) -> Result<(), RecordError>

Saves the record and preserves validation-style error reporting.

Source

fn create_sync(attrs: HashMap<String, Value>) -> Result<Self, RecordError>

Creates a new record from a string-keyed attribute map.

Source

fn insert_all_sync( records: Vec<HashMap<String, Value>>, ) -> Result<Vec<Self>, RecordError>

Inserts multiple records at once.

Source

fn upsert_sync( attrs: HashMap<String, Value>, unique_by: &[&str], ) -> Result<Self, RecordError>

Inserts a record, or updates it if a matching row already exists.

Source

fn upsert_all_sync( records: Vec<HashMap<String, Value>>, unique_by: &[&str], ) -> Result<Vec<Self>, RecordError>

Inserts or updates multiple records at once.

Source

fn update_attributes_sync( &mut self, attrs: HashMap<String, Value>, ) -> Result<(), RecordError>

Updates the record with the provided attributes and saves the result.

Source

fn destroy_sync(&mut self) -> Result<(), RecordError>

Deletes the record from the database and marks it destroyed.

Source

fn reload_sync(&mut self) -> Result<(), RecordError>

Reloads the record from the database.

Source

fn delete_sync(id: i64) -> Result<(), RecordError>

Deletes a row by primary key without instantiating a wrapper value.

Source

fn update_all_sync( conditions: HashMap<String, Value>, updates: HashMap<String, Value>, ) -> Result<u64, RecordError>

Updates all rows matching the provided conditions and returns the affected row count.

Source

fn destroy_all_sync( conditions: HashMap<String, Value>, ) -> Result<u64, RecordError>

Deletes all rows matching the provided conditions and returns the affected row count.

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§

Source§

impl<T: AsyncPersistence> Persistence for T