1use crate::behavior::TransactionQuery;
2
3#[cfg(any(feature = "postgresql", feature = "sqlite"))]
4use crate::behavior::WithQuery;
5
6#[cfg(any(feature = "postgresql", feature = "sqlite"))]
7use std::sync::Arc;
8
9#[derive(Default, Clone)]
31pub struct AlterTable {
32 pub(crate) _alter_table: String,
33 pub(crate) _ordered_actions: Vec<AlterTableActionItem>,
34 pub(crate) _raw_after: Vec<(AlterTableAction, String)>,
35 pub(crate) _raw_before: Vec<(AlterTableAction, String)>,
36 pub(crate) _raw: Vec<String>,
37
38 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
39 pub(crate) _rename: String,
40
41 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
42 pub(crate) _rename_to: String,
43}
44
45#[derive(PartialEq, Clone)]
46pub(crate) struct AlterTableActionItem(pub(crate) AlterTableOrderedAction, pub(crate) String);
47
48#[derive(PartialEq, Clone)]
50pub(crate) enum AlterTableOrderedAction {
51 Add,
52 Drop,
53
54 #[cfg(any(feature = "postgresql"))]
55 Alter,
56}
57
58#[derive(PartialEq, Clone)]
60pub enum AlterTableAction {
61 AlterTable,
62
63 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
64 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
65 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
66 Rename,
67
68 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
69 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
70 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
71 RenameTo,
72
73 #[cfg(not(any(feature = "postgresql")))]
74 Add,
75
76 #[cfg(not(any(feature = "postgresql")))]
77 Drop,
78}
79
80#[cfg(any(feature = "postgresql", feature = "sqlite"))]
81pub(crate) enum Combinator {
82 Except,
83 Intersect,
84 Union,
85}
86
87#[cfg(any(feature = "postgresql", feature = "sqlite"))]
113#[derive(Default, Clone)]
114pub struct CreateIndex {
115 pub(crate) _column: Vec<String>,
116 pub(crate) _index_name: String,
117 pub(crate) _create_index: bool,
118 pub(crate) _if_not_exists: bool,
119 pub(crate) _on: String,
120 pub(crate) _raw_after: Vec<(CreateIndexParams, String)>,
121 pub(crate) _raw_before: Vec<(CreateIndexParams, String)>,
122 pub(crate) _raw: Vec<String>,
123 pub(crate) _unique: bool,
124
125 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
126 pub(crate) _where: Vec<(LogicalOperator, String)>,
127
128 #[cfg(feature = "postgresql")]
129 pub(crate) _concurrently: bool,
130 #[cfg(feature = "postgresql")]
131 pub(crate) _include: Vec<String>,
132 #[cfg(feature = "postgresql")]
133 pub(crate) _only: bool,
134 #[cfg(feature = "postgresql")]
135 pub(crate) _using: String,
136}
137
138#[cfg(any(feature = "postgresql", feature = "sqlite"))]
140#[derive(PartialEq, Clone)]
141pub enum CreateIndexParams {
142 Column,
143 CreateIndex,
144 On,
145 Unique,
146
147 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
148 Where,
149
150 #[cfg(feature = "postgresql")]
151 Concurrently,
152 #[cfg(feature = "postgresql")]
153 Only,
154 #[cfg(feature = "postgresql")]
155 Using,
156 #[cfg(feature = "postgresql")]
157 Include,
158}
159
160#[derive(Default, Clone)]
196pub struct CreateTable {
197 pub(crate) _column: Vec<String>,
198 pub(crate) _constraint: Vec<String>,
199 pub(crate) _create_table: String,
200 pub(crate) _foreign_key: Vec<String>,
201 pub(crate) _primary_key: String,
202 pub(crate) _raw_after: Vec<(CreateTableParams, String)>,
203 pub(crate) _raw_before: Vec<(CreateTableParams, String)>,
204 pub(crate) _raw: Vec<String>,
205}
206
207#[derive(PartialEq, Clone)]
209pub enum CreateTableParams {
210 Column,
211 Constraint,
212 CreateTable,
213 ForeignKey,
214 PrimaryKey,
215}
216
217#[cfg(any(feature = "postgresql", feature = "sqlite"))]
242#[derive(Default, Clone)]
243pub struct DropIndex {
244 pub(crate) _drop_index: Vec<String>,
245 pub(crate) _if_exists: bool,
246 pub(crate) _raw_after: Vec<(DropIndexParams, String)>,
247 pub(crate) _raw_before: Vec<(DropIndexParams, String)>,
248 pub(crate) _raw: Vec<String>,
249}
250
251#[cfg(any(feature = "postgresql", feature = "sqlite"))]
253#[derive(PartialEq, Clone)]
254pub enum DropIndexParams {
255 DropIndex,
256}
257
258#[derive(Default, Clone)]
280pub struct DropTable {
281 pub(crate) _drop_table: Vec<String>,
282 pub(crate) _if_exists: bool,
283 pub(crate) _raw_after: Vec<(DropTableParams, String)>,
284 pub(crate) _raw_before: Vec<(DropTableParams, String)>,
285 pub(crate) _raw: Vec<String>,
286}
287
288#[derive(PartialEq, Clone)]
290pub enum DropTableParams {
291 DropTable,
292}
293
294#[derive(Default, Clone)]
316pub struct Delete {
317 pub(crate) _delete_from: String,
318 pub(crate) _raw_after: Vec<(DeleteClause, String)>,
319 pub(crate) _raw_before: Vec<(DeleteClause, String)>,
320 pub(crate) _raw: Vec<String>,
321 pub(crate) _where: Vec<(LogicalOperator, String)>,
322
323 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
324 pub(crate) _returning: Vec<String>,
325
326 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
327 pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery + Send + Sync>)>,
328}
329
330#[derive(PartialEq, Clone)]
332pub enum DeleteClause {
333 DeleteFrom,
334 Where,
335
336 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
337 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
338 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
339 Returning,
340
341 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
342 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
343 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
344 With,
345}
346
347#[derive(Default, Clone)]
370pub struct Insert {
371 pub(crate) _default_values: bool,
372 pub(crate) _on_conflict: String,
373 pub(crate) _overriding: String,
374 pub(crate) _raw_after: Vec<(InsertClause, String)>,
375 pub(crate) _raw_before: Vec<(InsertClause, String)>,
376 pub(crate) _raw: Vec<String>,
377 pub(crate) _select: Option<Select>,
378 pub(crate) _values: Vec<String>,
379
380 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
381 pub(crate) _returning: Vec<String>,
382
383 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
384 pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery + Send + Sync>)>,
385
386 #[cfg(not(feature = "sqlite"))]
387 pub(crate) _insert_into: String,
388
389 #[cfg(feature = "sqlite")]
390 pub(crate) _insert: (InsertVars, String),
391}
392
393#[cfg(feature = "sqlite")]
394#[derive(Default, Clone, PartialEq)]
395pub(crate) enum InsertVars {
396 #[default]
397 InsertInto,
398 InsertOr,
399 ReplaceInto,
400}
401
402#[derive(PartialEq, Clone)]
404pub enum InsertClause {
405 DefaultValues,
406 InsertInto,
407 OnConflict,
408 Overriding,
409 Select,
410 Values,
411
412 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
413 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
414 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
415 Returning,
416
417 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
418 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
419 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
420 With,
421
422 #[cfg(feature = "sqlite")]
423 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
424 InsertOr,
425
426 #[cfg(feature = "sqlite")]
427 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
428 ReplaceInto,
429}
430
431#[derive(Clone, PartialEq)]
432pub(crate) enum LogicalOperator {
433 And,
434 Or,
435}
436
437impl std::fmt::Display for LogicalOperator {
438 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
439 let v = match self {
440 LogicalOperator::And => "AND",
441 LogicalOperator::Or => "OR",
442 };
443 write!(f, "{}", v)
444 }
445}
446
447#[derive(Default, Clone)]
482pub struct Select {
483 pub(crate) _from: Vec<String>,
484 pub(crate) _group_by: Vec<String>,
485 pub(crate) _having: Vec<String>,
486 pub(crate) _join: Vec<String>,
487 pub(crate) _order_by: Vec<String>,
488 pub(crate) _raw_after: Vec<(SelectClause, String)>,
489 pub(crate) _raw_before: Vec<(SelectClause, String)>,
490 pub(crate) _raw: Vec<String>,
491 pub(crate) _select: Vec<String>,
492 pub(crate) _where: Vec<(LogicalOperator, String)>,
493 pub(crate) _window: Vec<String>,
494
495 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
496 pub(crate) _except: Vec<Self>,
497
498 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
499 pub(crate) _intersect: Vec<Self>,
500
501 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
502 pub(crate) _limit: String,
503
504 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
505 pub(crate) _offset: String,
506
507 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
508 pub(crate) _union: Vec<Self>,
509
510 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
511 pub(crate) _with: Vec<(String, Arc<dyn WithQuery + Send + Sync>)>,
512}
513
514#[derive(Clone, PartialEq)]
516pub enum SelectClause {
517 From,
518 GroupBy,
519 Having,
520 Join,
521 Limit,
522 Offset,
523 OrderBy,
524 Select,
525 Where,
526 Window,
527
528 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
529 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
530 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
531 Except,
532
533 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
534 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
535 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
536 Intersect,
537
538 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
539 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
540 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
541 Union,
542
543 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
544 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
545 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
546 With,
547}
548
549#[derive(Default)]
593pub struct Transaction {
594 pub(crate) _commit: Option<TransactionCommand>,
595 pub(crate) _ordered_commands: Vec<Box<dyn TransactionQuery>>,
596 pub(crate) _raw: Vec<String>,
597 pub(crate) _set_transaction: Option<TransactionCommand>,
598 pub(crate) _start_transaction: Option<TransactionCommand>,
599
600 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
601 pub(crate) _begin: Option<TransactionCommand>,
602
603 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
604 pub(crate) _end: Option<TransactionCommand>,
605}
606
607#[derive(PartialEq)]
609pub(crate) enum TrCmd {
610 Commit,
611 ReleaseSavepoint,
612 Rollback,
613 Savepoint,
614
615 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
616 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
617 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
618 Begin,
619
620 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
621 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
622 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
623 End,
624
625 #[cfg(not(feature = "sqlite"))]
626 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
627 SetTransaction,
628
629 #[cfg(not(feature = "sqlite"))]
630 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
631 StartTransaction,
632}
633
634#[derive(PartialEq)]
635pub(crate) struct TransactionCommand(pub(crate) TrCmd, pub(crate) String);
636
637#[derive(Default, Clone)]
660pub struct Update {
661 pub(crate) _raw_after: Vec<(UpdateClause, String)>,
662 pub(crate) _raw_before: Vec<(UpdateClause, String)>,
663 pub(crate) _raw: Vec<String>,
664 pub(crate) _set: Vec<String>,
665 pub(crate) _where: Vec<(LogicalOperator, String)>,
666
667 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
668 pub(crate) _from: Vec<String>,
669
670 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
671 pub(crate) _returning: Vec<String>,
672
673 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
674 pub(crate) _with: Vec<(String, std::sync::Arc<dyn crate::behavior::WithQuery + Send + Sync>)>,
675
676 #[cfg(not(feature = "sqlite"))]
677 pub(crate) _update: String,
678
679 #[cfg(feature = "sqlite")]
680 pub(crate) _update: (UpdateVars, String),
681
682 #[cfg(feature = "sqlite")]
683 pub(crate) _join: Vec<String>,
684}
685
686#[cfg(feature = "sqlite")]
687#[derive(Default, Clone, PartialEq)]
688pub(crate) enum UpdateVars {
689 #[default]
690 Update,
691 UpdateOr,
692}
693
694#[derive(PartialEq, Clone)]
696pub enum UpdateClause {
697 Set,
698 Update,
699 Where,
700
701 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
702 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
703 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
704 From,
705
706 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
707 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
708 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
709 Returning,
710
711 #[cfg(any(feature = "postgresql", feature = "sqlite"))]
712 #[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
713 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
714 With,
715
716 #[cfg(feature = "sqlite")]
717 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
718 UpdateOr,
719
720 #[cfg(feature = "sqlite")]
721 #[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
722 Join,
723}
724
725#[derive(Default, Clone)]
747pub struct Values {
748 pub(crate) _raw_after: Vec<(ValuesClause, String)>,
749 pub(crate) _raw_before: Vec<(ValuesClause, String)>,
750 pub(crate) _raw: Vec<String>,
751 pub(crate) _values: Vec<String>,
752}
753
754#[derive(PartialEq, Clone)]
756pub enum ValuesClause {
757 Values,
758}