use crate::behavior::TransactionQuery;
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
use crate::behavior::WithQuery;
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
use std::sync::Arc;
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) enum Combinator {
Except,
Intersect,
Union,
}
#[derive(Default, Clone)]
pub struct Delete {
pub(crate) _delete_from: String,
pub(crate) _raw_after: Vec<(DeleteClause, String)>,
pub(crate) _raw_before: Vec<(DeleteClause, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _where: Vec<(LogicalOperator, String)>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _returning: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery>)>,
}
#[derive(PartialEq, Clone)]
pub enum DeleteClause {
DeleteFrom,
Where,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Returning,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
With,
}
#[derive(Default, Clone)]
pub struct Insert {
pub(crate) _default_values: bool,
pub(crate) _on_conflict: String,
pub(crate) _overriding: String,
pub(crate) _raw_after: Vec<(InsertClause, String)>,
pub(crate) _raw_before: Vec<(InsertClause, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _select: Option<Select>,
pub(crate) _values: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _returning: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery>)>,
#[cfg(not(feature = "sqlite"))]
pub(crate) _insert_into: String,
#[cfg(feature = "sqlite")]
pub(crate) _insert: (InsertVars, String),
}
#[cfg(feature = "sqlite")]
#[derive(Default, Clone, PartialEq)]
pub(crate) enum InsertVars {
#[default]
InsertInto,
InsertOr,
ReplaceInto,
}
#[derive(PartialEq, Clone)]
pub enum InsertClause {
DefaultValues,
InsertInto,
OnConflict,
Overriding,
Select,
Values,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Returning,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
With,
#[cfg(feature = "sqlite")]
InsertOr,
#[cfg(feature = "sqlite")]
ReplaceInto,
}
#[derive(Clone, PartialEq)]
pub(crate) enum LogicalOperator {
And,
Or,
}
#[derive(Default, Clone)]
pub struct Select {
pub(crate) _from: Vec<String>,
pub(crate) _group_by: Vec<String>,
pub(crate) _having: Vec<String>,
pub(crate) _join: Vec<String>,
pub(crate) _order_by: Vec<String>,
pub(crate) _raw_after: Vec<(SelectClause, String)>,
pub(crate) _raw_before: Vec<(SelectClause, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _select: Vec<String>,
pub(crate) _where: Vec<(LogicalOperator, String)>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _except: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _intersect: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _limit: String,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _offset: String,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _union: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _with: Vec<(String, Arc<dyn WithQuery>)>,
}
#[derive(Clone, PartialEq)]
pub enum SelectClause {
From,
GroupBy,
Having,
Join,
Limit,
Offset,
OrderBy,
Select,
Where,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Except,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Intersect,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Union,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
With,
}
#[derive(Default)]
pub struct Transaction {
pub(crate) _commit: Option<TransactionCommand>,
pub(crate) _ordered_commands: Vec<Box<dyn TransactionQuery>>,
pub(crate) _raw: Vec<String>,
pub(crate) _set_transaction: Option<TransactionCommand>,
pub(crate) _start_transaction: Option<TransactionCommand>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _begin: Option<TransactionCommand>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _end: Option<TransactionCommand>,
}
#[derive(PartialEq)]
pub(crate) enum TrCmd {
Commit,
ReleaseSavepoint,
Rollback,
Savepoint,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Begin,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
End,
#[cfg(not(feature = "sqlite"))]
SetTransaction,
#[cfg(not(feature = "sqlite"))]
StartTransaction,
}
#[derive(PartialEq)]
pub(crate) struct TransactionCommand(pub(crate) TrCmd, pub(crate) String);
#[derive(Default, Clone)]
pub struct Update {
pub(crate) _raw_after: Vec<(UpdateClause, String)>,
pub(crate) _raw_before: Vec<(UpdateClause, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _set: Vec<String>,
pub(crate) _where: Vec<(LogicalOperator, String)>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _from: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _returning: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery>)>,
#[cfg(not(feature = "sqlite"))]
pub(crate) _update: String,
#[cfg(feature = "sqlite")]
pub(crate) _update: (UpdateVars, String),
#[cfg(feature = "sqlite")]
pub(crate) _join: Vec<String>,
}
#[cfg(feature = "sqlite")]
#[derive(Default, Clone, PartialEq)]
pub(crate) enum UpdateVars {
#[default]
Update,
UpdateOr,
}
#[derive(PartialEq, Clone)]
pub enum UpdateClause {
Set,
Update,
Where,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
From,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Returning,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
With,
#[cfg(feature = "sqlite")]
UpdateOr,
#[cfg(feature = "sqlite")]
Join,
}
#[derive(Default, Clone)]
pub struct Values {
pub(crate) _raw_after: Vec<(ValuesClause, String)>,
pub(crate) _raw_before: Vec<(ValuesClause, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _values: Vec<String>,
}
#[derive(PartialEq, Clone)]
pub enum ValuesClause {
Values,
}