sql_query_builder/
structure.rs

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/// Builder to contruct a [AlterTable] command.
10///
11/// Basic API
12///
13/// ```
14/// use sql_query_builder as sql;
15///
16/// let query = sql::AlterTable::new()
17///   .alter_table("users")
18///   .add("COLUMN id serial primary key")
19///   .as_string();
20///
21/// # let expected = "ALTER TABLE users ADD COLUMN id serial primary key";
22/// # assert_eq!(expected, query);
23/// ```
24///
25/// Output
26///
27/// ```sql
28/// ALTER TABLE users ADD COLUMN id serial primary key
29/// ```
30#[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/// Actions used to build the sequencial part of [AlterTable]
49#[derive(PartialEq, Clone)]
50pub(crate) enum AlterTableOrderedAction {
51  Add,
52  Drop,
53
54  #[cfg(any(feature = "postgresql"))]
55  Alter,
56}
57
58/// All available params to be used in [AlterTable::raw_before] and [AlterTable::raw_after] methods on [AlterTable] builder
59#[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/// Builder to contruct a [CreateIndex] command. Available only for the crate features `postgresql` and `sqlite`.
88///
89/// Basic API
90///
91/// ```
92/// # #[cfg(any(feature = "postgresql", feature = "sqlite"))]
93/// # {
94/// use sql_query_builder as sql;
95///
96/// let query = sql::CreateIndex::new()
97///   .create_index("users_name_idx")
98///   .on("users")
99///   .column("name")
100///   .as_string();
101///
102/// # let expected = "CREATE INDEX users_name_idx ON users (name)";
103/// # assert_eq!(expected, query);
104/// # }
105/// ```
106///
107/// Output
108///
109/// ```sql
110/// CREATE INDEX users_name_idx ON users (name)
111/// ```
112#[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/// All available params to be used in [CreateIndex::raw_before] and [CreateIndex::raw_after] methods on [CreateIndex] builder
139#[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/// Builder to contruct a [CreateTable] command.
161///
162/// Basic API
163///
164/// ```
165/// use sql_query_builder as sql;
166///
167/// let query = sql::CreateTable::new()
168///   .create_table("users")
169///   .column("id serial primary key")
170///   .column("login varchar(40) not null")
171///   .constraint("users_login_key unique(login)")
172///   .as_string();
173///
174/// # let expected = "\
175/// #   CREATE TABLE users (\
176/// #     id serial primary key, \
177/// #     login varchar(40) not null, \
178/// #     CONSTRAINT users_login_key unique(login)\
179/// #   )\
180/// # ";
181/// # assert_eq!(expected, query);
182/// ```
183///
184///
185/// Output (indented for readability)
186///
187/// ```sql
188/// CREATE TABLE users (
189///   id serial primary key,
190///   login varchar(40) not null,
191///   created_at timestamp not null,
192///   CONSTRAINT users_login_key unique(login)
193/// )
194/// ```
195#[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/// All available params to be used in [CreateTable::raw_before] and [CreateTable::raw_after] methods on [CreateTable] builder
208#[derive(PartialEq, Clone)]
209pub enum CreateTableParams {
210  Column,
211  Constraint,
212  CreateTable,
213  ForeignKey,
214  PrimaryKey,
215}
216
217/// Builder to contruct a [DropIndex] command. Available only for the crate features `postgresql` and `sqlite`.
218///
219/// Basic API
220///
221/// ```
222/// # #[cfg(any(feature = "postgresql", feature = "sqlite"))]
223/// # {
224/// use sql_query_builder as sql;
225///
226/// let query = sql::DropIndex::new()
227///   .drop_index("users_name_idx")
228///   .as_string();
229///
230/// # let expected = "DROP INDEX users_name_idx";
231/// # assert_eq!(expected, query);
232/// # }
233/// ```
234///
235///
236/// Output
237///
238/// ```sql
239/// DROP INDEX users_name_idx
240/// ```
241#[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/// All available params to be used in [DropIndex::raw_before] and [DropIndex::raw_after] methods on [DropIndex] builder
252#[cfg(any(feature = "postgresql", feature = "sqlite"))]
253#[derive(PartialEq, Clone)]
254pub enum DropIndexParams {
255  DropIndex,
256}
257
258/// Builder to contruct a [DropTable] command.
259///
260/// Basic API
261///
262/// ```
263/// use sql_query_builder as sql;
264///
265/// let query = sql::DropTable::new()
266///   .drop_table("users")
267///   .as_string();
268///
269/// # let expected = "DROP TABLE users";
270/// # assert_eq!(expected, query);
271/// ```
272///
273///
274/// Output
275///
276/// ```sql
277/// DROP TABLE users
278/// ```
279#[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/// All available params to be used in [DropTable::raw_before] and [DropTable::raw_after] methods on [DropTable] builder
289#[derive(PartialEq, Clone)]
290pub enum DropTableParams {
291  DropTable,
292}
293
294/// Builder to contruct a [Delete] command.
295///
296/// Basic API
297///
298/// ```
299/// use sql_query_builder as sql;
300///
301/// let query = sql::Delete::new()
302///   .delete_from("users")
303///   .where_clause("id = $1")
304///   .as_string();
305///
306/// # let expected = "DELETE FROM users WHERE id = $1";
307/// # assert_eq!(expected, query);
308/// ```
309///
310/// Output
311///
312/// ```sql
313/// DELETE FROM users WHERE id = $1
314/// ```
315#[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/// All available clauses to be used in [Delete::raw_before] and [Delete::raw_after] methods on [Delete] builder
331#[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/// Builder to contruct a [Insert] command.
348///
349/// Basic API
350///
351/// ```
352/// use sql_query_builder as sql;
353///
354/// let query = sql::Insert::new()
355///   .insert_into("users (login, name)")
356///   .values("('foo', 'Foo')")
357///   .values("('bar', 'Bar')")
358///   .as_string();
359///
360/// # let expected = "INSERT INTO users (login, name) VALUES ('foo', 'Foo'), ('bar', 'Bar')";
361/// # assert_eq!(expected, query);
362/// ```
363///
364/// Output
365///
366/// ```sql
367/// INSERT INTO users (login, name) VALUES ('foo', 'Foo'), ('bar', 'Bar')
368/// ```
369#[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/// All available clauses to be used in [Insert::raw_before] and [Insert::raw_after] methods on [Insert] builder
403#[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/// Builder to contruct a [Select] command.
448///
449/// Basic API
450///
451/// ```
452/// use sql_query_builder as sql;
453///
454/// let query = sql::Select::new()
455///   .select("*")
456///   .from("users")
457///   .inner_join("orders ON users.login = orders.login")
458///   .where_clause("user.login = $1")
459///   .order_by("created_at desc")
460///   .as_string();
461///
462/// # let expected = "\
463/// #   SELECT * \
464/// #   FROM users \
465/// #   INNER JOIN orders ON users.login = orders.login \
466/// #   WHERE user.login = $1 \
467/// #   ORDER BY created_at desc\
468/// # ";
469/// # assert_eq!(expected, query);
470/// ```
471///
472/// Output (indented for readability)
473///
474/// ```sql
475/// SELECT *
476/// FROM users
477/// INNER JOIN orders ON users.login = orders.login
478/// WHERE user.login = $1
479/// ORDER BY created_at desc
480/// ```
481#[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/// All available clauses to be used in [Select::raw_before] and [Select::raw_after] methods on [Select] builder
515#[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/// Builder to contruct a [Transaction] block.
550///
551/// Basic API
552///
553/// ```
554/// # #[cfg(not(feature = "sqlite"))]
555/// # {
556/// use sql_query_builder as sql;
557///
558/// let insert_foo = sql::Insert::new()
559///   .insert_into("users (login, name)")
560///   .values("('foo', 'Foo')");
561///
562/// let update_foo = sql::Update::new()
563///   .update("users")
564///   .set("name = 'Bar'")
565///   .where_clause("login = 'foo'");
566///
567/// let query = sql::Transaction::new()
568///   .start_transaction("isolation level serializable")
569///   .insert(insert_foo)
570///   .update(update_foo)
571///   .commit("transaction")
572///   .as_string();
573///
574/// # let expected = "\
575/// # START TRANSACTION isolation level serializable; \
576/// # INSERT INTO users (login, name) VALUES ('foo', 'Foo'); \
577/// # UPDATE users SET name = 'Bar' WHERE login = 'foo'; \
578/// # COMMIT transaction;\
579/// # ";
580/// # assert_eq!(expected, query);
581/// # }
582/// ```
583///
584/// Output (indented for readability)
585///
586/// ```sql
587/// START TRANSACTION isolation level serializable;
588/// INSERT INTO users (login, name) VALUES ('foo', 'Foo');
589/// UPDATE users SET name = 'Bar' WHERE login = 'foo';
590/// COMMIT transaction;
591/// ```
592#[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/// Commands used in to build a [Transaction]
608#[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/// Builder to contruct a [Update] command.
638///
639/// Basic API
640///
641/// ```
642/// use sql_query_builder as sql;
643///
644/// let query = sql::Update::new()
645///   .update("users")
646///   .set("name = 'Bar'")
647///   .where_clause("id = $1")
648///   .as_string();
649///
650/// # let expected = "UPDATE users SET name = 'Bar' WHERE id = $1";
651/// # assert_eq!(expected, query);
652/// ```
653///
654/// Output
655///
656/// ```sql
657/// UPDATE users SET name = 'Bar' WHERE id = $1
658/// ```
659#[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/// All available clauses to be used in [Update::raw_before] and [Update::raw_after] methods on [Update] builder
695#[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/// Builder to contruct a [Values] command.
726///
727/// Basic API
728///
729/// ```
730/// use sql_query_builder as sql;
731///
732/// let query = sql::Values::new()
733///   .values("('foo', 'Foo')")
734///   .values("('bar', 'Bar')")
735///   .as_string();
736///
737/// # let expected = "VALUES ('foo', 'Foo'), ('bar', 'Bar')";
738/// # assert_eq!(expected, query);
739/// ```
740///
741/// Output
742///
743/// ```sql
744/// VALUES ('foo', 'Foo'), ('bar', 'Bar')
745/// ```
746#[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/// All available clauses to be used in [Values::raw_before] and [Values::raw_after] methods on [Values] builder
755#[derive(PartialEq, Clone)]
756pub enum ValuesClause {
757  Values,
758}