1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::ast::*;
use crate::common::symbol::Symbol;
/// Represents constraints applied to a single column in a table definition.
#[derive(Debug, Clone, PartialEq)]
pub enum ColumnConstraint {
/// Allows the column to store `NULL` values.
Null,
/// Prevents the column from storing `NULL` values (`NOT NULL`).
NotNull,
/// Specifies a default fallback value for the column when not provided in an INSERT statement (`DEFAULT <expr>`).
Default(Expr),
/// Enforces that all values in this column must be distinct across the table (`UNIQUE`).
Unique,
/// Identifies this column as the primary key of the table (`PRIMARY KEY`).
PrimaryKey,
/// Validates values in this column against a boolean expression before saving (`CHECK (<expr>)`).
Check(Expr),
/// Defines a foreign key constraint linking this column to a target table and columns (`REFERENCES table(columns)`).
References {
/// The referenced foreign table path.
table: ObjectName,
/// The referenced columns in the foreign table.
columns: Vec<Symbol>,
/// Referential action applied on deletion of a parent record (`ON DELETE`).
on_delete: Option<ReferentialAction>,
/// Referential action applied on modification of a parent record (`ON UPDATE`).
on_update: Option<ReferentialAction>,
},
/// Automatically increment the column value (e.g. MySQL `AUTO_INCREMENT` or SQLite `AUTOINCREMENT`).
AutoIncrement,
}