Documetation for the query module
This commit is contained in:
parent
69d5c701ee
commit
a9b6f8cc83
@ -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<F>(mut self, _: F) -> SelectTwo<E, F>
|
||||
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<F>(mut self, _: F) -> SelectTwoMany<E, F>
|
||||
where
|
||||
F: EntityTrait,
|
||||
|
@ -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<A>
|
||||
where
|
||||
@ -17,6 +19,7 @@ where
|
||||
pub(crate) model: A,
|
||||
}
|
||||
|
||||
/// Perform a delete operation on multiple models
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DeleteMany<E>
|
||||
where
|
||||
|
@ -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<M>(mut self, model: &M, tbl_alias: &str) -> Self
|
||||
where
|
||||
M: ModelTrait,
|
||||
|
@ -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<A>
|
||||
where
|
||||
@ -106,6 +107,7 @@ where
|
||||
Self::new().add_many(models)
|
||||
}
|
||||
|
||||
/// Add a Model to Self
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn add<M>(mut self, m: M) -> Self
|
||||
where
|
||||
@ -139,6 +141,7 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Add many Models to Self
|
||||
pub fn add_many<M, I>(mut self, models: I) -> Self
|
||||
where
|
||||
M: IntoActiveModel<A>,
|
||||
|
@ -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<E>
|
||||
where
|
||||
@ -13,6 +14,7 @@ where
|
||||
pub(crate) entity: PhantomData<E>,
|
||||
}
|
||||
|
||||
/// Defines a structure to perform a SELECT operation on two Models
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SelectTwo<E, F>
|
||||
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<E, F>
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<A>
|
||||
where
|
||||
@ -17,6 +19,7 @@ where
|
||||
pub(crate) model: A,
|
||||
}
|
||||
|
||||
/// Defines an UPDATE operation on multiple ActiveModels
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UpdateMany<E>
|
||||
where
|
||||
@ -177,6 +180,7 @@ impl<E> UpdateMany<E>
|
||||
where
|
||||
E: EntityTrait,
|
||||
{
|
||||
/// Add the models to update to Self
|
||||
pub fn set<A>(mut self, model: A) -> Self
|
||||
where
|
||||
A: ActiveModelTrait<Entity = E>,
|
||||
@ -190,6 +194,7 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Creates a [SimpleExpr] from a column
|
||||
pub fn col_expr<T>(mut self, col: T, expr: SimpleExpr) -> Self
|
||||
where
|
||||
T: IntoIden,
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user