use crate::{Dml, Expr, SchemaObject, Select};
#[derive(Clone, Debug, PartialEq)]
pub struct CreateTable {
pub temp: bool,
pub if_not_exists: bool,
pub schema_table: SchemaObject,
pub body: CreateTableBody,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CreateIndex {
pub unique: bool,
pub if_not_exists: bool,
pub schema_index: SchemaObject,
pub table_name: String,
pub indexed_cols: Vec<IndexedColumn>,
pub where_cond: Option<Expr>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CreateView {
pub temp: bool,
pub if_not_exists: bool,
pub schema_view: SchemaObject,
pub cols: Vec<String>,
pub select: Select,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CreateTrigger {
pub temp: bool,
pub if_not_exists: bool,
pub schema_trigger: SchemaObject,
pub timing: TriggerTiming,
pub event: TriggerEvent,
pub table_name: String,
pub when_cond: Option<Expr>,
pub statements: Vec<Dml>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct AlterTable {
pub schema_table: SchemaObject,
pub action: AlterTableAction,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DropTable {
pub if_exists: bool,
pub schema_table: SchemaObject,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DropIndex {
pub if_exists: bool,
pub schema_index: SchemaObject,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DropView {
pub if_exists: bool,
pub schema_view: SchemaObject,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DropTrigger {
pub if_exists: bool,
pub schema_trigger: SchemaObject,
}
#[derive(Clone, Debug, PartialEq)]
pub enum AlterTableAction {
RenameTable(String),
RenameColumn(String, String),
AddColumn(ColumnDef),
DropColumn(String),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ColumnDef {
pub name: String,
pub col_type: Option<TypeName>,
pub constraints: Vec<ColumnConstraint>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TypeName {
pub affinity: Affinity,
pub size: Option<TypeSize>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Affinity {
Integer,
Real,
Numeric,
Text,
Blob,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TypeSize {
MaxSize(String),
TypeSize(String, String),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ColumnConstraint {
pub name: Option<String>,
pub ty: ColumnConstraintType,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ColumnConstraintType {
PrimaryKey {
asc: bool, auto_inc: bool,
},
NotNull,
Unique,
Check(Expr),
Default(Expr),
ForeignKey(ForeignKey),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ForeignKey {
pub schema_table: SchemaObject,
pub cols: Vec<String>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TableConstraint {
pub name: Option<String>,
pub cols: Vec<IndexedColumn>,
pub ty: TableConstraintType,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TableConstraintType {
PrimaryKey,
Unique,
}
#[derive(Clone, Debug, PartialEq)]
pub struct IndexedColumn {
pub name: String,
pub asc: bool, }
#[derive(Clone, Debug, PartialEq)]
pub enum CreateTableBody {
Select(Select),
Columns {
cols: Vec<ColumnDef>,
constraints: Vec<TableConstraint>,
options: Vec<TableOption>,
},
}
#[derive(Clone, Debug, PartialEq)]
pub enum TableOption {
WithoutRowid,
Strict,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TriggerTiming {
Before,
After,
InsteadOf,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TriggerEvent {
Delete,
Insert,
Update(Vec<String>), }