use crate::behavior::TransactionQuery;
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
use crate::behavior::WithQuery;
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
use std::sync::Arc;
#[derive(Default, Clone)]
pub struct AlterTable {
pub(crate) _alter_table: String,
pub(crate) _ordered_actions: Vec<AlterTableActionItem>,
pub(crate) _raw_after: Vec<(AlterTableAction, String)>,
pub(crate) _raw_before: Vec<(AlterTableAction, String)>,
pub(crate) _raw: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _rename: String,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _rename_to: String,
}
#[derive(PartialEq, Clone)]
pub(crate) struct AlterTableActionItem(pub(crate) AlterTableOrderedAction, pub(crate) String);
#[derive(PartialEq, Clone)]
pub(crate) enum AlterTableOrderedAction {
Add,
Drop,
#[cfg(any(feature = "postgresql", feature = "mysql"))]
Alter,
#[cfg(feature = "mysql")]
Rename,
}
#[derive(PartialEq, Clone)]
pub enum AlterTableAction {
AlterTable,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
Rename,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
RenameTo,
#[cfg(not(any(feature = "postgresql")))]
Add,
#[cfg(not(any(feature = "postgresql")))]
Drop,
}
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) enum Combinator {
Except,
Intersect,
Union,
}
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(Default, Clone)]
pub struct CreateIndex {
pub(crate) _column: Vec<String>,
pub(crate) _index_name: String,
pub(crate) _create_index: bool,
pub(crate) _on: String,
pub(crate) _raw_after: Vec<(CreateIndexParams, String)>,
pub(crate) _raw_before: Vec<(CreateIndexParams, String)>,
pub(crate) _raw: Vec<String>,
pub(crate) _unique: bool,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _if_not_exists: bool,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _where: Vec<(LogicalOperator, String)>,
#[cfg(any(feature = "postgresql", feature = "mysql"))]
pub(crate) _using: String,
#[cfg(feature = "postgresql")]
pub(crate) _concurrently: bool,
#[cfg(feature = "postgresql")]
pub(crate) _include: Vec<String>,
#[cfg(feature = "postgresql")]
pub(crate) _only: bool,
#[cfg(feature = "mysql")]
pub(crate) _fulltext: bool,
#[cfg(feature = "mysql")]
pub(crate) _lock: String,
#[cfg(feature = "mysql")]
pub(crate) _spatial: bool,
}
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(PartialEq, Clone)]
pub enum CreateIndexParams {
Column,
CreateIndex,
On,
Unique,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Where,
#[cfg(any(feature = "postgresql", feature = "mysql"))]
Using,
#[cfg(feature = "postgresql")]
Concurrently,
#[cfg(feature = "postgresql")]
Only,
#[cfg(feature = "postgresql")]
Include,
#[cfg(feature = "mysql")]
Fulltext,
#[cfg(feature = "mysql")]
Lock,
#[cfg(feature = "mysql")]
Spatial,
}
#[derive(Default, Clone)]
pub struct CreateTable {
pub(crate) _column: Vec<String>,
pub(crate) _constraint: Vec<String>,
pub(crate) _create_table: String,
pub(crate) _foreign_key: Vec<String>,
pub(crate) _primary_key: String,
pub(crate) _raw_after: Vec<(CreateTableParams, String)>,
pub(crate) _raw_before: Vec<(CreateTableParams, String)>,
pub(crate) _raw: Vec<String>,
}
#[derive(PartialEq, Clone)]
pub enum CreateTableParams {
Column,
Constraint,
CreateTable,
ForeignKey,
PrimaryKey,
}
#[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", feature = "mysql"))]
pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery + Send + Sync>)>,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _returning: Vec<String>,
#[cfg(any(feature = "sqlite", feature = "mysql"))]
pub(crate) _order_by: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _delete: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _from: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _join: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _limit: String,
#[cfg(feature = "mysql")]
pub(crate) _partition: Vec<String>,
}
#[derive(PartialEq, Clone)]
pub enum DeleteClause {
DeleteFrom,
Where,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
With,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
Returning,
#[cfg(any(feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
OrderBy,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Limit,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Delete,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
From,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Join,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Partition,
}
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(Default, Clone)]
pub struct DropIndex {
pub(crate) _drop_index: Vec<String>,
pub(crate) _if_exists: bool,
pub(crate) _raw_after: Vec<(DropIndexParams, String)>,
pub(crate) _raw_before: Vec<(DropIndexParams, String)>,
pub(crate) _raw: Vec<String>,
}
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(PartialEq, Clone)]
pub enum DropIndexParams {
DropIndex,
}
#[derive(Default, Clone)]
pub struct DropTable {
pub(crate) _drop_table: Vec<String>,
pub(crate) _if_exists: bool,
pub(crate) _raw_after: Vec<(DropTableParams, String)>,
pub(crate) _raw_before: Vec<(DropTableParams, String)>,
pub(crate) _raw: Vec<String>,
}
#[derive(PartialEq, Clone)]
pub enum DropTableParams {
DropTable,
}
#[derive(Default, Clone)]
pub struct Insert {
pub(crate) _insert_into: String,
pub(crate) _insert_variance: InsertVariance,
pub(crate) _raw: Vec<String>,
pub(crate) _raw_after: Vec<(InsertClause, String)>,
pub(crate) _raw_before: Vec<(InsertClause, String)>,
pub(crate) _select: Option<Select>,
pub(crate) _values: Vec<String>,
pub(crate) _values_variance: ValuesVariance,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub(crate) _on_conflict: 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 + Send + Sync>)>,
#[cfg(not(any(feature = "sqlite", feature = "mysql")))]
pub(crate) _overriding: String,
#[cfg(feature = "sqlite")]
pub(crate) _insert_or: String,
#[cfg(feature = "sqlite")]
pub(crate) _replace_into: String,
#[cfg(feature = "mysql")]
pub(crate) _column: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _insert: String,
#[cfg(feature = "mysql")]
pub(crate) _into: String,
#[cfg(feature = "mysql")]
pub(crate) _on_duplicate_key_update: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _partition: Vec<String>,
#[cfg(feature = "mysql")]
pub(crate) _set: Vec<String>,
}
#[derive(PartialEq, Clone)]
pub enum InsertClause {
DefaultValues,
InsertInto,
OnConflict,
Overriding,
Select,
Values,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
Returning,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
With,
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
InsertOr,
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
ReplaceInto,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Column,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Insert,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Into,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
OnDuplicateKeyUpdate,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Partition,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Set,
}
#[derive(Default, PartialEq, Clone)]
pub enum InsertVariance {
#[default]
InsertInto,
#[cfg(feature = "sqlite")]
InsertOr,
#[cfg(feature = "sqlite")]
ReplaceInto,
#[cfg(feature = "mysql")]
InsertSplitted,
}
#[derive(Default, PartialEq, Clone)]
pub enum ValuesVariance {
#[default]
InsertValues,
InsertSelect,
#[cfg(not(feature = "mysql"))]
InsertDefaultValues,
#[cfg(feature = "mysql")]
InsertSet,
#[cfg(feature = "mysql")]
InsertValuesRow,
}
#[derive(Clone, PartialEq)]
pub(crate) enum LogicalOperator {
And,
Or,
}
impl std::fmt::Display for LogicalOperator {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let v = match self {
LogicalOperator::And => "AND",
LogicalOperator::Or => "OR",
};
write!(f, "{}", v)
}
}
#[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)>,
pub(crate) _window: Vec<String>,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _except: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _intersect: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _limit: String,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _offset: String,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _union: Vec<Self>,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _with: Vec<(String, Arc<dyn WithQuery + Send + Sync>)>,
#[cfg(feature = "mysql")]
pub(crate) _partition: Vec<String>,
}
#[derive(Clone, PartialEq)]
pub enum SelectClause {
From,
GroupBy,
Having,
Join,
Limit,
Offset,
OrderBy,
Select,
Where,
Window,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Except,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Intersect,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Union,
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
With,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Partition,
}
#[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", feature = "mysql"))]
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", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Begin,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
End,
#[cfg(not(feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
SetTransaction,
#[cfg(not(feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
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 + Send + Sync>)>,
#[cfg(any(feature = "sqlite", feature = "mysql"))]
pub(crate) _order_by: Vec<String>,
#[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 = "mysql")]
pub(crate) _limit: 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"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
From,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
Returning,
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
With,
#[cfg(any(feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
OrderBy,
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
UpdateOr,
#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
Join,
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Limit,
}
#[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,
}