Documetation for the executor module

This commit is contained in:
Charles Chege 2021-10-29 10:38:55 +03:00
parent a9b6f8cc83
commit 817e9bdd23
7 changed files with 78 additions and 2 deletions

View File

@ -4,13 +4,16 @@ use crate::{
use sea_query::DeleteStatement; use sea_query::DeleteStatement;
use std::future::Future; use std::future::Future;
/// Handles DELETE operations in a ActiveModel using [DeleteStatement]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Deleter { pub struct Deleter {
query: DeleteStatement, query: DeleteStatement,
} }
/// The result of a DELETE operation
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct DeleteResult { pub struct DeleteResult {
/// The number of rows affected by the DELETE operation
pub rows_affected: u64, pub rows_affected: u64,
} }
@ -18,6 +21,7 @@ impl<'a, A: 'a> DeleteOne<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
/// Execute a DELETE operation on one ActiveModel
pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_ pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -31,6 +35,7 @@ impl<'a, E> DeleteMany<E>
where where
E: EntityTrait, E: EntityTrait,
{ {
/// Execute a DELETE operation on many ActiveModels
pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_ pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -41,10 +46,12 @@ where
} }
impl Deleter { impl Deleter {
/// Instantiate a new [Deleter] by passing it a [DeleteStatement]
pub fn new(query: DeleteStatement) -> Self { pub fn new(query: DeleteStatement) -> Self {
Self { query } Self { query }
} }
/// Execute a DELETE operation
pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_ pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,

View File

@ -1,16 +1,24 @@
/// Defines the result of executing an operation
#[derive(Debug)] #[derive(Debug)]
pub struct ExecResult { pub struct ExecResult {
/// The type of result from the execution depending on the feature flag enabled
/// to choose a database backend
pub(crate) result: ExecResultHolder, pub(crate) result: ExecResultHolder,
} }
/// Holds a result depending on the database backend chosen by the feature flag
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum ExecResultHolder { pub(crate) enum ExecResultHolder {
/// Holds the result of executing an operation on a MySQL database
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
SqlxMySql(sqlx::mysql::MySqlQueryResult), SqlxMySql(sqlx::mysql::MySqlQueryResult),
/// Holds the result of executing an operation on a PostgreSQL database
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
SqlxPostgres(sqlx::postgres::PgQueryResult), SqlxPostgres(sqlx::postgres::PgQueryResult),
/// Holds the result of executing an operation on a SQLite database
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
SqlxSqlite(sqlx::sqlite::SqliteQueryResult), SqlxSqlite(sqlx::sqlite::SqliteQueryResult),
/// Holds the result of executing an operation on the Mock database
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
Mock(crate::MockExecResult), Mock(crate::MockExecResult),
} }
@ -18,6 +26,7 @@ pub(crate) enum ExecResultHolder {
// ExecResult // // ExecResult //
impl ExecResult { impl ExecResult {
/// Get the last id after `AUTOINCREMENT` is done on the primary key
pub fn last_insert_id(&self) -> u64 { pub fn last_insert_id(&self) -> u64 {
match &self.result { match &self.result {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
@ -40,6 +49,7 @@ impl ExecResult {
} }
} }
/// Get the number of rows affedted by the operation
pub fn rows_affected(&self) -> u64 { pub fn rows_affected(&self) -> u64 {
match &self.result { match &self.result {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]

View File

@ -5,6 +5,7 @@ use crate::{
use sea_query::{FromValueTuple, InsertStatement, ValueTuple}; use sea_query::{FromValueTuple, InsertStatement, ValueTuple};
use std::{future::Future, marker::PhantomData}; use std::{future::Future, marker::PhantomData};
/// Defines a structure to perform INSERT operations in an ActiveModel
#[derive(Debug)] #[derive(Debug)]
pub struct Inserter<A> pub struct Inserter<A>
where where
@ -15,11 +16,13 @@ where
model: PhantomData<A>, model: PhantomData<A>,
} }
/// The result of an INSERT operation on an ActiveModel
#[derive(Debug)] #[derive(Debug)]
pub struct InsertResult<A> pub struct InsertResult<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
/// The id performed when AUTOINCREMENT was performed on the PrimaryKey
pub last_insert_id: <<<A as ActiveModelTrait>::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType, pub last_insert_id: <<<A as ActiveModelTrait>::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType,
} }
@ -27,6 +30,7 @@ impl<A> Insert<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
/// Execute an insert operation
#[allow(unused_mut)] #[allow(unused_mut)]
pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_ pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_
where where
@ -53,6 +57,7 @@ impl<A> Inserter<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
/// Instantiate a new insert operation
pub fn new(primary_key: Option<ValueTuple>, query: InsertStatement) -> Self { pub fn new(primary_key: Option<ValueTuple>, query: InsertStatement) -> Self {
Self { Self {
primary_key, primary_key,
@ -61,6 +66,7 @@ where
} }
} }
/// Execute an insert operation
pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_ pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,

View File

@ -4,8 +4,10 @@ use futures::Stream;
use sea_query::{Alias, Expr, SelectStatement}; use sea_query::{Alias, Expr, SelectStatement};
use std::{marker::PhantomData, pin::Pin}; use std::{marker::PhantomData, pin::Pin};
/// Pin a Model so that stream operations can be performed on the model
pub type PinBoxStream<'db, Item> = Pin<Box<dyn Stream<Item = Item> + 'db>>; pub type PinBoxStream<'db, Item> = Pin<Box<dyn Stream<Item = Item> + 'db>>;
/// Defined a structure to handle pagination of a result from a query operation on a Model
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Paginator<'db, C, S> pub struct Paginator<'db, C, S>
where where

View File

@ -3,6 +3,7 @@ use crate::debug_print;
use crate::{DbErr, SelectGetableValue, SelectorRaw, Statement}; use crate::{DbErr, SelectGetableValue, SelectorRaw, Statement};
use std::fmt; use std::fmt;
/// Defines the result of a query operation on a Model
#[derive(Debug)] #[derive(Debug)]
pub struct QueryResult { pub struct QueryResult {
pub(crate) row: QueryResultRow, pub(crate) row: QueryResultRow,
@ -19,13 +20,18 @@ pub(crate) enum QueryResultRow {
Mock(crate::MockRow), Mock(crate::MockRow),
} }
/// Constrain any type trying to get a Row in a database
pub trait TryGetable: Sized { pub trait TryGetable: Sized {
/// Ensure the type implements this method
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>; fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>;
} }
/// An error from trying to get a row from a Model
#[derive(Debug)] #[derive(Debug)]
pub enum TryGetError { pub enum TryGetError {
/// A database error was encountered as defined in [crate::DbErr]
DbErr(DbErr), DbErr(DbErr),
/// A null value was encountered
Null, Null,
} }
@ -41,6 +47,7 @@ impl From<TryGetError> for DbErr {
// QueryResult // // QueryResult //
impl QueryResult { impl QueryResult {
/// Get a Row from a Column
pub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, DbErr> pub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, DbErr>
where where
T: TryGetable, T: TryGetable,
@ -48,6 +55,7 @@ impl QueryResult {
Ok(T::try_get(self, pre, col)?) Ok(T::try_get(self, pre, col)?)
} }
/// Perform query operations on multiple Columns
pub fn try_get_many<T>(&self, pre: &str, cols: &[String]) -> Result<T, DbErr> pub fn try_get_many<T>(&self, pre: &str, cols: &[String]) -> Result<T, DbErr>
where where
T: TryGetableMany, T: TryGetableMany,
@ -306,7 +314,9 @@ try_getable_all!(uuid::Uuid);
// TryGetableMany // // TryGetableMany //
/// Perform a query on multiple columns
pub trait TryGetableMany: Sized { pub trait TryGetableMany: Sized {
/// THe method to perform a query on multiple columns
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError>; fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError>;
/// ``` /// ```
@ -453,8 +463,9 @@ fn try_get_many_with_slice_len_of(len: usize, cols: &[String]) -> Result<(), Try
} }
// TryFromU64 // // TryFromU64 //
/// Try to convert a type to a u64
pub trait TryFromU64: Sized { pub trait TryFromU64: Sized {
/// The method to convert the type to a u64
fn try_from_u64(n: u64) -> Result<Self, DbErr>; fn try_from_u64(n: u64) -> Result<Self, DbErr>;
} }

View File

@ -11,6 +11,7 @@ use std::pin::Pin;
#[cfg(feature = "with-json")] #[cfg(feature = "with-json")]
use crate::JsonValue; use crate::JsonValue;
/// Defines a type to do `SELECT` operations though a [SelectStatement] on a Model
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Selector<S> pub struct Selector<S>
where where
@ -20,6 +21,7 @@ where
selector: S, selector: S,
} }
/// Performs a raw `SELECT` operation on a model
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SelectorRaw<S> pub struct SelectorRaw<S>
where where
@ -29,12 +31,16 @@ where
selector: S, selector: S,
} }
/// Used to enforce constraints on any type that wants to perform SELECT queries
pub trait SelectorTrait { pub trait SelectorTrait {
#[allow(missing_docs)]
type Item: Sized; type Item: Sized;
/// The method to perform a query on a Model
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr>; fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr>;
} }
/// Perform an operation on an entity that can yield a Value
#[derive(Debug)] #[derive(Debug)]
pub struct SelectGetableValue<T, C> pub struct SelectGetableValue<T, C>
where where
@ -45,6 +51,7 @@ where
model: PhantomData<T>, model: PhantomData<T>,
} }
/// Defines a type to get a Model
#[derive(Debug)] #[derive(Debug)]
pub struct SelectModel<M> pub struct SelectModel<M>
where where
@ -53,6 +60,7 @@ where
model: PhantomData<M>, model: PhantomData<M>,
} }
/// Defines a type to get two Modelss
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SelectTwoModel<M, N> pub struct SelectTwoModel<M, N>
where where
@ -105,6 +113,7 @@ impl<E> Select<E>
where where
E: EntityTrait, E: EntityTrait,
{ {
/// Perform a Select operation on a Model using a [Statement]
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
pub fn from_raw_sql(self, stmt: Statement) -> SelectorRaw<SelectModel<E::Model>> { pub fn from_raw_sql(self, stmt: Statement) -> SelectorRaw<SelectModel<E::Model>> {
SelectorRaw { SelectorRaw {
@ -113,6 +122,7 @@ where
} }
} }
/// Return a [Selector] from `Self` that wraps a [SelectModel]
pub fn into_model<M>(self) -> Selector<SelectModel<M>> pub fn into_model<M>(self) -> Selector<SelectModel<M>>
where where
M: FromQueryResult, M: FromQueryResult,
@ -123,6 +133,7 @@ where
} }
} }
/// Get a selectable Model as a [JsonValue] for SQL JSON operations
#[cfg(feature = "with-json")] #[cfg(feature = "with-json")]
pub fn into_json(self) -> Selector<SelectModel<JsonValue>> { pub fn into_json(self) -> Selector<SelectModel<JsonValue>> {
Selector { Selector {
@ -239,6 +250,7 @@ where
Selector::<SelectGetableValue<T, C>>::with_columns(self.query) Selector::<SelectGetableValue<T, C>>::with_columns(self.query)
} }
/// Get one Model from a SELECT operation
pub async fn one<'a, C>(self, db: &C) -> Result<Option<E::Model>, DbErr> pub async fn one<'a, C>(self, db: &C) -> Result<Option<E::Model>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -246,6 +258,7 @@ where
self.into_model().one(db).await self.into_model().one(db).await
} }
/// Get all the Models from a SELECT operation
pub async fn all<'a, C>(self, db: &C) -> Result<Vec<E::Model>, DbErr> pub async fn all<'a, C>(self, db: &C) -> Result<Vec<E::Model>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -253,6 +266,7 @@ where
self.into_model().all(db).await self.into_model().all(db).await
} }
/// Stream the results of a SELECT operation on a Model
pub async fn stream<'a: 'b, 'b, C>( pub async fn stream<'a: 'b, 'b, C>(
self, self,
db: &'a C, db: &'a C,
@ -263,6 +277,7 @@ where
self.into_model().stream(db).await self.into_model().stream(db).await
} }
/// Paginate the results of a SELECT operation on a Model
pub fn paginate<'a, C>( pub fn paginate<'a, C>(
self, self,
db: &'a C, db: &'a C,
@ -274,6 +289,7 @@ where
self.into_model().paginate(db, page_size) self.into_model().paginate(db, page_size)
} }
/// Perform a `COUNT` operation on a items on a Model using pagination
pub async fn count<'a, C>(self, db: &'a C) -> Result<usize, DbErr> pub async fn count<'a, C>(self, db: &'a C) -> Result<usize, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -287,6 +303,7 @@ where
E: EntityTrait, E: EntityTrait,
F: EntityTrait, F: EntityTrait,
{ {
/// Perform a conversion into a [SelectTwoModel]
pub fn into_model<M, N>(self) -> Selector<SelectTwoModel<M, N>> pub fn into_model<M, N>(self) -> Selector<SelectTwoModel<M, N>>
where where
M: FromQueryResult, M: FromQueryResult,
@ -298,6 +315,7 @@ where
} }
} }
/// Convert the Models into JsonValue
#[cfg(feature = "with-json")] #[cfg(feature = "with-json")]
pub fn into_json(self) -> Selector<SelectTwoModel<JsonValue, JsonValue>> { pub fn into_json(self) -> Selector<SelectTwoModel<JsonValue, JsonValue>> {
Selector { Selector {
@ -306,6 +324,7 @@ where
} }
} }
/// Get one Model from a Select operation
pub async fn one<'a, C>(self, db: &C) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr> pub async fn one<'a, C>(self, db: &C) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -313,6 +332,7 @@ where
self.into_model().one(db).await self.into_model().one(db).await
} }
/// Get all Models from a Select operation
pub async fn all<'a, C>(self, db: &C) -> Result<Vec<(E::Model, Option<F::Model>)>, DbErr> pub async fn all<'a, C>(self, db: &C) -> Result<Vec<(E::Model, Option<F::Model>)>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -320,6 +340,7 @@ where
self.into_model().all(db).await self.into_model().all(db).await
} }
/// Stream the results of a Select operation on a Model
pub async fn stream<'a: 'b, 'b, C>( pub async fn stream<'a: 'b, 'b, C>(
self, self,
db: &'a C, db: &'a C,
@ -330,6 +351,7 @@ where
self.into_model().stream(db).await self.into_model().stream(db).await
} }
/// Paginate the results of a select operation on two models
pub fn paginate<'a, C>( pub fn paginate<'a, C>(
self, self,
db: &'a C, db: &'a C,
@ -341,6 +363,7 @@ where
self.into_model().paginate(db, page_size) self.into_model().paginate(db, page_size)
} }
/// Perform a count on the paginated results
pub async fn count<'a, C>(self, db: &'a C) -> Result<usize, DbErr> pub async fn count<'a, C>(self, db: &'a C) -> Result<usize, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -354,6 +377,7 @@ where
E: EntityTrait, E: EntityTrait,
F: EntityTrait, F: EntityTrait,
{ {
/// Performs a conversion to [Selector]
fn into_model<M, N>(self) -> Selector<SelectTwoModel<M, N>> fn into_model<M, N>(self) -> Selector<SelectTwoModel<M, N>>
where where
M: FromQueryResult, M: FromQueryResult,
@ -365,6 +389,7 @@ where
} }
} }
/// Convert the results to JSON
#[cfg(feature = "with-json")] #[cfg(feature = "with-json")]
pub fn into_json(self) -> Selector<SelectTwoModel<JsonValue, JsonValue>> { pub fn into_json(self) -> Selector<SelectTwoModel<JsonValue, JsonValue>> {
Selector { Selector {
@ -373,6 +398,7 @@ where
} }
} }
/// Select one Model
pub async fn one<'a, C>(self, db: &C) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr> pub async fn one<'a, C>(self, db: &C) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -380,6 +406,7 @@ where
self.into_model().one(db).await self.into_model().one(db).await
} }
/// Stream the result of the operation
pub async fn stream<'a: 'b, 'b, C>( pub async fn stream<'a: 'b, 'b, C>(
self, self,
db: &'a C, db: &'a C,
@ -390,6 +417,7 @@ where
self.into_model().stream(db).await self.into_model().stream(db).await
} }
/// Get all the Models from the select operation
pub async fn all<'a, C>(self, db: &C) -> Result<Vec<(E::Model, Vec<F::Model>)>, DbErr> pub async fn all<'a, C>(self, db: &C) -> Result<Vec<(E::Model, Vec<F::Model>)>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -428,6 +456,7 @@ where
} }
} }
/// Get a Model from a Select operation
pub async fn one<'a, C>(mut self, db: &C) -> Result<Option<S::Item>, DbErr> pub async fn one<'a, C>(mut self, db: &C) -> Result<Option<S::Item>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -441,6 +470,7 @@ where
} }
} }
/// Get all results from a Select operation
pub async fn all<'a, C>(self, db: &C) -> Result<Vec<S::Item>, DbErr> pub async fn all<'a, C>(self, db: &C) -> Result<Vec<S::Item>, DbErr>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -454,6 +484,7 @@ where
Ok(models) Ok(models)
} }
/// Stream the results of the operation
pub async fn stream<'a: 'b, 'b, C>( pub async fn stream<'a: 'b, 'b, C>(
self, self,
db: &'a C, db: &'a C,
@ -469,6 +500,7 @@ where
}))) })))
} }
/// Paginate the result of a select operation on a Model
pub fn paginate<'a, C>(self, db: &'a C, page_size: usize) -> Paginator<'a, C, S> pub fn paginate<'a, C>(self, db: &'a C, page_size: usize) -> Paginator<'a, C, S>
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -499,7 +531,7 @@ where
} }
} }
/// Create `SelectorRaw` from Statment and columns. Executing this `SelectorRaw` will /// Create `SelectorRaw` from Statement and columns. Executing this `SelectorRaw` will
/// return a type `T` which implement `TryGetableMany`. /// return a type `T` which implement `TryGetableMany`.
pub fn with_columns<T, C>(stmt: Statement) -> SelectorRaw<SelectGetableValue<T, C>> pub fn with_columns<T, C>(stmt: Statement) -> SelectorRaw<SelectGetableValue<T, C>>
where where

View File

@ -4,14 +4,17 @@ use crate::{
use sea_query::UpdateStatement; use sea_query::UpdateStatement;
use std::future::Future; use std::future::Future;
/// Defines an update operation
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Updater { pub struct Updater {
query: UpdateStatement, query: UpdateStatement,
check_record_exists: bool, check_record_exists: bool,
} }
/// The result of an update operation on an ActiveModel
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct UpdateResult { pub struct UpdateResult {
/// The rows affected by the update operation
pub rows_affected: u64, pub rows_affected: u64,
} }
@ -19,6 +22,7 @@ impl<'a, A: 'a> UpdateOne<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
/// Execute an update operation on an ActiveModel
pub async fn exec<'b, C>(self, db: &'b C) -> Result<A, DbErr> pub async fn exec<'b, C>(self, db: &'b C) -> Result<A, DbErr>
where where
C: ConnectionTrait<'b>, C: ConnectionTrait<'b>,
@ -32,6 +36,7 @@ impl<'a, E> UpdateMany<E>
where where
E: EntityTrait, E: EntityTrait,
{ {
/// Execute an update operation on multiple ActiveModels
pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<UpdateResult, DbErr>> + '_ pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<UpdateResult, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,
@ -42,6 +47,7 @@ where
} }
impl Updater { impl Updater {
/// Instantiate an update using an [UpdateStatement]
pub fn new(query: UpdateStatement) -> Self { pub fn new(query: UpdateStatement) -> Self {
Self { Self {
query, query,
@ -49,11 +55,13 @@ impl Updater {
} }
} }
/// Check if a record exists on the ActiveModel to perform the update operation on
pub fn check_record_exists(mut self) -> Self { pub fn check_record_exists(mut self) -> Self {
self.check_record_exists = true; self.check_record_exists = true;
self self
} }
/// Execute an update operation
pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<UpdateResult, DbErr>> + '_ pub fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<UpdateResult, DbErr>> + '_
where where
C: ConnectionTrait<'a>, C: ConnectionTrait<'a>,