drizzle_migrations/sqlite/ddl.rs
1//! `SQLite` DDL types - re-exports from `drizzle_types` plus parsing types
2
3// Re-export everything from drizzle_types::sqlite::ddl
4pub use drizzle_types::sqlite::ddl::*;
5
6// =============================================================================
7// Parsing Types - Used during introspection to parse CREATE TABLE statements
8// =============================================================================
9
10/// Parsed table options from CREATE TABLE SQL
11#[derive(Debug, Clone, Default)]
12pub struct ParsedTable {
13 /// Whether the table has STRICT mode enabled
14 pub strict: bool,
15 /// Whether the table is WITHOUT ROWID
16 pub without_rowid: bool,
17 /// Unique constraints parsed from the DDL
18 pub uniques: Vec<ParsedUnique>,
19}
20
21/// Parse table options from CREATE TABLE SQL
22///
23/// This is a simple parser that extracts basic table options.
24/// For full constraint parsing, use the more complete introspection methods.
25#[must_use]
26pub fn parse_table_ddl(sql: &str) -> ParsedTable {
27 let (strict, without_rowid) = crate::sqlite::introspect::parse_table_options(sql);
28 ParsedTable {
29 strict,
30 without_rowid,
31 uniques: Vec::new(), // Unique constraints are parsed separately via pragma
32 }
33}
34
35/// Parsed generated column information from CREATE TABLE SQL
36#[derive(Debug, Clone)]
37pub struct ParsedGenerated {
38 /// SQL expression for generation (e.g., "`first_name` || ' ' || `last_name`")
39 pub expression: String,
40 /// Generation type: stored or virtual
41 pub gen_type: GeneratedType,
42}
43
44/// Parsed unique constraint from CREATE TABLE SQL
45#[derive(Debug, Clone)]
46pub struct ParsedUnique {
47 /// Constraint name (if explicitly named)
48 pub name: Option<String>,
49 /// Column names in the unique constraint
50 pub columns: Vec<String>,
51}
52
53/// Parsed foreign key constraint from CREATE TABLE SQL
54#[derive(Debug, Clone)]
55pub struct ParsedForeignKey {
56 /// Constraint name (if explicitly named)
57 pub name: Option<String>,
58 /// Source columns
59 pub columns: Vec<String>,
60 /// Referenced table
61 pub table_to: String,
62 /// Referenced columns
63 pub columns_to: Vec<String>,
64 /// ON DELETE action
65 pub on_delete: Option<String>,
66 /// ON UPDATE action
67 pub on_update: Option<String>,
68}
69
70/// Parsed primary key information from CREATE TABLE SQL
71#[derive(Debug, Clone)]
72pub struct ParsedPrimaryKey {
73 /// Column names in the primary key
74 pub columns: Vec<String>,
75 /// Whether any column is autoincrement
76 pub autoincrement: bool,
77}
78
79/// Parsed check constraint from CREATE TABLE SQL
80#[derive(Debug, Clone)]
81pub struct ParsedCheck {
82 /// Constraint name (if explicitly named)
83 pub name: Option<String>,
84 /// Check expression
85 pub expression: String,
86}