diff --git a/src/query/combine.rs b/src/query/combine.rs index c03906ea..a3dcc275 100644 --- a/src/query/combine.rs +++ b/src/query/combine.rs @@ -7,6 +7,7 @@ use sea_query::{Alias, ColumnRef, Iden, Order, SeaRc, SelectExpr, SelectStatemen macro_rules! select_def { ( $ident: ident, $str: expr ) => { + /// Implements the traits [Iden] and [IdenStatic] for a type #[derive(Debug, Clone, Copy)] pub struct $ident; @@ -54,6 +55,7 @@ where self } + /// Selects and Entity and returns it together with the Entity from `Self` pub fn select_also(mut self, _: F) -> SelectTwo where F: EntityTrait, @@ -62,6 +64,7 @@ where SelectTwo::new(self.into_query()) } + /// Makes a SELECT operation in conjunction to another relation pub fn select_with(mut self, _: F) -> SelectTwoMany where F: EntityTrait, diff --git a/src/query/delete.rs b/src/query/delete.rs index e5cefdef..c7df0c7d 100644 --- a/src/query/delete.rs +++ b/src/query/delete.rs @@ -5,9 +5,11 @@ use crate::{ use core::marker::PhantomData; use sea_query::{DeleteStatement, IntoIden}; +/// Defines the structure for a delete operation #[derive(Clone, Debug)] pub struct Delete; +/// Perform a delete operation on a model #[derive(Clone, Debug)] pub struct DeleteOne where @@ -17,6 +19,7 @@ where pub(crate) model: A, } +/// Perform a delete operation on multiple models #[derive(Clone, Debug)] pub struct DeleteMany where diff --git a/src/query/helper.rs b/src/query/helper.rs index bf762fc9..46f8c895 100644 --- a/src/query/helper.rs +++ b/src/query/helper.rs @@ -11,9 +11,12 @@ pub use sea_query::{Condition, ConditionalStatement, DynIden, JoinType, Order, O // LINT: when the column does not appear in tables selected from // LINT: when there is a group by clause, but some columns don't have aggregate functions // LINT: when the join table or column does not exists +/// Constraints for any type that needs to perform select statements on a Model pub trait QuerySelect: Sized { + #[allow(missing_docs)] type QueryStatement; + /// Add the select SQL statement fn query(&mut self) -> &mut SelectStatement; /// Clear the selection list @@ -164,9 +167,12 @@ pub trait QuerySelect: Sized { } // LINT: when the column does not appear in tables selected from +/// Performs ORDER BY operations pub trait QueryOrder: Sized { + #[allow(missing_docs)] type QueryStatement: OrderedStatement; + /// Add the query to perform an ORDER BY operation fn query(&mut self) -> &mut SelectStatement; /// Add an order_by expression @@ -234,9 +240,12 @@ pub trait QueryOrder: Sized { } // LINT: when the column does not appear in tables selected from +/// Perform a FILTER opertation on a statement pub trait QueryFilter: Sized { + #[allow(missing_docs)] type QueryStatement: ConditionalStatement; + /// Add the query to perform a FILTER on fn query(&mut self) -> &mut Self::QueryStatement; /// Add an AND WHERE expression @@ -372,6 +381,7 @@ pub trait QueryFilter: Sized { self } + /// Perform a check to determine table belongs to a Model through it's name alias fn belongs_to_tbl_alias(mut self, model: &M, tbl_alias: &str) -> Self where M: ModelTrait, diff --git a/src/query/insert.rs b/src/query/insert.rs index 5e504a0c..f862ccba 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -5,6 +5,7 @@ use crate::{ use core::marker::PhantomData; use sea_query::{InsertStatement, ValueTuple}; +/// Performs INSERT operations on a ActiveModel #[derive(Debug)] pub struct Insert where @@ -106,6 +107,7 @@ where Self::new().add_many(models) } + /// Add a Model to Self #[allow(clippy::should_implement_trait)] pub fn add(mut self, m: M) -> Self where @@ -139,6 +141,7 @@ where self } + /// Add many Models to Self pub fn add_many(mut self, models: I) -> Self where M: IntoActiveModel, diff --git a/src/query/select.rs b/src/query/select.rs index 1b0c93c3..adfb07db 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -4,6 +4,7 @@ use core::marker::PhantomData; pub use sea_query::JoinType; use sea_query::{DynIden, IntoColumnRef, SeaRc, SelectStatement, SimpleExpr}; +/// Defines a structure to perform select operations #[derive(Clone, Debug)] pub struct Select where @@ -13,6 +14,7 @@ where pub(crate) entity: PhantomData, } +/// Defines a structure to perform a SELECT operation on two Models #[derive(Clone, Debug)] pub struct SelectTwo where @@ -23,6 +25,7 @@ where pub(crate) entity: PhantomData<(E, F)>, } +/// Defines a structure to perform a SELECT operation on many Models #[derive(Clone, Debug)] pub struct SelectTwoMany where @@ -33,7 +36,9 @@ where pub(crate) entity: PhantomData<(E, F)>, } +/// Performs a conversion to [SimpleExpr] pub trait IntoSimpleExpr { + /// Method to perform the conversion fn into_simple_expr(self) -> SimpleExpr; } diff --git a/src/query/traits.rs b/src/query/traits.rs index f0045f52..0517cc64 100644 --- a/src/query/traits.rs +++ b/src/query/traits.rs @@ -1,7 +1,9 @@ use crate::{DbBackend, Statement}; use sea_query::QueryStatementBuilder; +/// Enforces a set of constraints to any type performing queries on a Model or ActiveModel pub trait QueryTrait { + /// Constrain the QueryStatement to [QueryStatementBuilder] trait type QueryStatement: QueryStatementBuilder; /// Get a mutable ref to the query builder diff --git a/src/query/update.rs b/src/query/update.rs index fec7757c..177d9d9e 100644 --- a/src/query/update.rs +++ b/src/query/update.rs @@ -5,9 +5,11 @@ use crate::{ use core::marker::PhantomData; use sea_query::{IntoIden, SimpleExpr, UpdateStatement}; +/// Defines a structure to perform UPDATE query operations on a ActiveModel #[derive(Clone, Debug)] pub struct Update; +/// Defines an UPDATE operation on one ActiveModel #[derive(Clone, Debug)] pub struct UpdateOne where @@ -17,6 +19,7 @@ where pub(crate) model: A, } +/// Defines an UPDATE operation on multiple ActiveModels #[derive(Clone, Debug)] pub struct UpdateMany where @@ -177,6 +180,7 @@ impl UpdateMany where E: EntityTrait, { + /// Add the models to update to Self pub fn set(mut self, model: A) -> Self where A: ActiveModelTrait, @@ -190,6 +194,7 @@ where self } + /// Creates a [SimpleExpr] from a column pub fn col_expr(mut self, col: T, expr: SimpleExpr) -> Self where T: IntoIden, diff --git a/src/query/util.rs b/src/query/util.rs index 5fc88950..b23804f2 100644 --- a/src/query/util.rs +++ b/src/query/util.rs @@ -1,8 +1,11 @@ use crate::{database::*, QueryTrait, Statement}; +/// This structure provides debug capabilities #[derive(Debug)] pub struct DebugQuery<'a, Q, T> { + /// The query to debug pub query: &'a Q, + /// The value of the query pub value: T, } @@ -12,6 +15,7 @@ macro_rules! debug_query_build { where Q: QueryTrait, { + /// This macro builds a [Statement] when invoked pub fn build(&self) -> Statement { let func = $db_expr; let db_backend = func(self);