[−][src]Struct orma::DbEntity
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]
T: DbData + Serialize + DeserializeOwned,
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]
&'_ mut self,
conn: &'_ Connection
) -> Result<(), DbError>
Inserts a new record into the associated table
pub async fn update<'_, '_>(
&'_ mut self,
conn: &'_ Connection
) -> Result<(), DbError>
[src]
&'_ mut self,
conn: &'_ Connection
) -> Result<(), DbError>
Persists the record
pub async fn delete<'_, '_>(
&'_ mut self,
conn: &'_ Connection
) -> Result<(), DbError>
[src]
&'_ mut self,
conn: &'_ Connection
) -> Result<(), DbError>
Performs a record deletion
pub async fn find_by<'_, '_, '_, '_>(
conn: &'_ Connection,
filter: (&'_ str, &'_ [&'_ (dyn ToSql + Sync)])
) -> Result<Option<Self>, DbError>
[src]
conn: &'_ Connection,
filter: (&'_ str, &'_ [&'_ (dyn ToSql + Sync)])
) -> Result<Option<Self>, DbError>
Searches for a record where filter over data column (JSONB) matches provided parameters.
Example
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]
conn: &'_ Connection,
filter: Option<(&'_ str, &'_ [&'_ (dyn ToSql + Sync)])>,
sorting: Option<&'_ [&'_ str]>,
offset: i64,
limit: i64
) -> Result<Vec<Self>, DbError>
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
DbEntity::<User>::find_all( db_conn, ( "data->>'user_name'=$1", &["some_name"], Some(&["data->>'user_name' DESC"]), 0, 100, ), );
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for DbEntity<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for DbEntity<T> where
T: Send,
T: Send,
impl<T> Sync for DbEntity<T> where
T: Sync,
T: Sync,
impl<T> Unpin for DbEntity<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for DbEntity<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T, A, P> Access<T> for P where
A: Access<T>,
P: Deref<Target = A>,
[src]
A: Access<T>,
P: Deref<Target = A>,
type Guard = <A as Access<T>>::Guard
A guard object containing the value and keeping it alive. Read more
fn load(&self) -> <P as Access<T>>::Guard
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
[src]
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,