[][src]Struct orma::DbEntity

pub struct DbEntity<T> where
    T: DbData + Serialize + DeserializeOwned
{ pub id: Uuid, pub version: i32, pub data: T, }

This struct is used to create a mapping for a data table.

Fields

id: Uuid

This is the effective primary key of the record. Its also used to build relations with other tables

version: i32

This field is used as a record check and identifies possible conflicts for parallel operations. version should always autoinc on record update

data: T

The real information that a data table record is containing

Implementations

impl<T> DbEntity<T> where
    T: DbData + Serialize + DeserializeOwned
[src]

pub fn new(id: Uuid, version: i32, data: T) -> Self[src]

Simple method used to create a new record

pub fn from_data(data: T) -> Self[src]

Given a data this method uses DbData#find_table_id_and_version to find a possible candidate for record or creates a new one that will need to be persisted with the insert method.

pub fn from_row(row: &Row) -> Result<Self, DbError>[src]

Given a database row (id, version, data) returns a DbEntity.

pub fn from_rows(rows: &[Row]) -> Result<Vec<Self>, DbError>[src]

Given a database rows of (id, version, data) tuples returns a Vec of DbEntity.

pub async fn insert<'a, '_, '_>(
    &'_ mut self,
    conn: &'_ Connection
) -> Result<(), DbError>
[src]

Inserts a new record into the associated table

pub async fn update<'_, '_>(
    &'_ mut self,
    conn: &'_ Connection
) -> Result<(), DbError>
[src]

Persists the record

pub async fn delete<'_, '_>(
    &'_ mut self,
    conn: &'_ Connection
) -> Result<(), DbError>
[src]

Performs a record deletion

pub async fn find_by<'_, '_, '_, '_>(
    conn: &'_ Connection,
    filter: (&'_ str, &'_ [&'_ (dyn ToSql + Sync)])
) -> Result<Option<Self>, DbError>
[src]

Searches for a record where filter over data column (JSONB) matches provided parameters.

Example

This example is not tested
DbEntity::<User>::find_by(db_conn, ("data->>'user_name'=$1", &["some_name"]));

pub async fn find_all<'_, '_, '_, '_, '_, '_>(
    conn: &'_ Connection,
    filter: Option<(&'_ str, &'_ [&'_ (dyn ToSql + Sync)])>,
    sorting: Option<&'_ [&'_ str]>,
    offset: i64,
    limit: i64
) -> Result<Vec<Self>, DbError>
[src]

Searching all matching records defined by filter clause (first element of the filter tuple)
A sorting clause can be given.
Limit and offset define the perimeter of the query result.

Example

This example is not tested
DbEntity::<User>::find_all(
   db_conn,
   (
       "data->>'user_name'=$1",
       &["some_name"],
       Some(&["data->>'user_name' DESC"]),
       0,
       100,
   ),
);

Trait Implementations

impl<T> Deref for DbEntity<T> where
    T: DbData + Serialize + DeserializeOwned
[src]

type Target = T

The resulting type after dereferencing.

Auto Trait Implementations

impl<T> RefUnwindSafe for DbEntity<T> where
    T: RefUnwindSafe

impl<T> Send for DbEntity<T> where
    T: Send

impl<T> Sync for DbEntity<T> where
    T: Sync

impl<T> Unpin for DbEntity<T> where
    T: Unpin

impl<T> UnwindSafe for DbEntity<T> where
    T: UnwindSafe

Blanket Implementations

impl<T, A, P> Access<T> for P where
    A: Access<T>,
    P: Deref<Target = A>, 
[src]

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, A> DynAccess<T> for A where
    A: Access<T>,
    <A as Access<T>>::Guard: 'static, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,