|
| 1 | +use super::{ |
| 2 | + ConflictClause, Expression, Identifier, QualifiedTableName, ReturningClause, SelectStatement, |
| 3 | + SetClause, |
| 4 | +}; |
| 5 | + |
1 | 6 | /// An AST for [INSERT](https://www.sqlite.org/lang_insert.html) SQL statement.
|
2 | 7 | #[derive(Debug, PartialEq)]
|
3 |
| -pub struct InsertStatement {} |
| 8 | +pub struct InsertStatement { |
| 9 | + pub conflict_clause: ConflictClause, |
| 10 | + |
| 11 | + /// TODO: Change the type, as QualifiedTableName contains indexing type |
| 12 | + /// which is not applicable for insert statements |
| 13 | + pub table_name: QualifiedTableName, |
| 14 | + |
| 15 | + pub columns: Vec<Identifier>, |
| 16 | + |
| 17 | + pub values: InsertValues, |
| 18 | + |
| 19 | + pub upsert_clause: Option<Vec<UpsertClause>>, |
| 20 | + |
| 21 | + pub returning_clause: Vec<ReturningClause>, |
| 22 | +} |
| 23 | + |
| 24 | +/// The values to insert into the table. |
| 25 | +#[derive(Debug, PartialEq)] |
| 26 | +pub enum InsertValues { |
| 27 | + /// The values to insert into the table. |
| 28 | + Values(Vec<Expression>), |
| 29 | + |
| 30 | + /// The values to insert into the table from a select statement. |
| 31 | + Select(SelectStatement), |
| 32 | + |
| 33 | + /// The values to insert into the table from a default value. |
| 34 | + DefaultValues, |
| 35 | +} |
| 36 | + |
| 37 | +/// The upsert clause to update the table with the new values. |
| 38 | +#[derive(Debug, PartialEq)] |
| 39 | +pub struct UpsertClause { |
| 40 | + pub conflict_target: Option<UpsertConflictTarget>, |
| 41 | + pub action: UpsertAction, |
| 42 | +} |
| 43 | + |
| 44 | +/// The [conflict target](https://www.sqlite.org/lang_upsert.html#upsert_conflict_target) |
| 45 | +/// to update the table with the new values. |
| 46 | +#[derive(Debug, PartialEq)] |
| 47 | +pub struct UpsertConflictTarget { |
| 48 | + pub columns: Vec<Identifier>, |
| 49 | + pub where_clause: Option<Expression>, |
| 50 | +} |
| 51 | + |
| 52 | +/// The [action](https://www.sqlite.org/lang_upsert.html#upsert_action) to take when a conflict occurs. |
| 53 | +#[derive(Debug, PartialEq)] |
| 54 | +pub enum UpsertAction { |
| 55 | + /// The action to take when a conflict occurs. |
| 56 | + Nothing, |
| 57 | + |
| 58 | + /// The action to take when a conflict occurs. |
| 59 | + Update(UpsertUpdate), |
| 60 | +} |
| 61 | + |
| 62 | +/// The [update set](https://www.sqlite.org/lang_upsert.html) action to take when a conflict occurs. |
| 63 | +#[derive(Debug, PartialEq)] |
| 64 | +pub struct UpsertUpdate { |
| 65 | + pub set_clauses: Vec<SetClause>, |
| 66 | + pub where_clause: Option<Expression>, |
| 67 | +} |
0 commit comments