Expand description
SQLite DDL (Data Definition Language) entity types
This module provides two complementary types for each DDL entity:
*Deftypes - Const-friendly definitions using onlyCopytypes (&'static str,bool) for compile-time schema definitions- Runtime types - Full types with
Cow<'static, str>for serde serialization/deserialization
§Design Pattern
┌─────────────────────────────────────────────────────────────────────────┐
│ Compile Time (const) Runtime (serde) │
│ ───────────────────── ──────────────── │
│ │
│ const DEF: TableDef = ...; let table: Table = DEF.into_table(); │
│ const COLS: &[ColumnDef] = ... let cols: Vec<Column> = ... │
│ │
│ Uses: &'static str, bool Uses: Cow<'static, str>, Vec, Option │
│ All types are Copy Supports serde, owned strings │
└─────────────────────────────────────────────────────────────────────────┘§Examples
§Compile-time Schema Definition
use drizzle_types::sqlite::ddl::{TableDef, ColumnDef};
// These are all const - zero runtime allocation
const USERS_TABLE: TableDef = TableDef::new("users").strict();
const USERS_COLUMNS: &[ColumnDef] = &[
ColumnDef::new("users", "id", "INTEGER").primary_key().autoincrement(),
ColumnDef::new("users", "name", "TEXT").not_null(),
ColumnDef::new("users", "email", "TEXT").unique(),
];§Converting to Runtime Types
use drizzle_types::sqlite::ddl::{TableDef, Table};
const DEF: TableDef = TableDef::new("users").strict();
// Convert when you need serde or runtime manipulation
let table: Table = DEF.into_table();§Runtime Deserialization
ⓘ
use drizzle_types::sqlite::ddl::Table;
let table: Table = serde_json::from_str(r#"{"name": "users", "strict": true}"#)?;Re-exports§
pub use sql::TableSql;
Modules§
- sql
- SQL generation for SQLite DDL types
Structs§
- Check
Constraint - Runtime check constraint entity
- Check
Constraint Def - Const-friendly check constraint definition
- Column
- Runtime column entity for serde serialization.
- Column
Def - Const-friendly column definition for compile-time schema definitions.
- Foreign
Key - Runtime foreign key constraint entity
- Foreign
KeyDef - Const-friendly foreign key definition
- Generated
- Generated column configuration (runtime)
- Generated
Def - Generated column configuration (const-friendly)
- Index
- Runtime index entity for serde serialization
- Index
Column - Runtime index column entity for serde serialization
- Index
Column Def - Const-friendly index column specification
- Index
Def - Const-friendly index definition
- Primary
Key - Runtime primary key constraint entity
- Primary
KeyDef - Const-friendly primary key definition
- Table
- Runtime table entity for serde serialization.
- Table
Def - Const-friendly table definition for compile-time schema definitions.
- Unique
Constraint - Runtime unique constraint entity
- Unique
Constraint Def - Const-friendly unique constraint definition
- View
- Runtime view entity
- ViewDef
- Const-friendly view definition
Enums§
- Generated
Type - Generated column type
- Index
Origin - Index origin - how the index was created
- Referential
Action - Foreign key referential action
- Sqlite
Entity - Unified SQLite DDL entity enum for serialization
Constants§
- ENTITY_
TYPE_ CHECKS - Entity type discriminator for check constraints
- ENTITY_
TYPE_ COLUMNS - Entity type discriminator for columns
- ENTITY_
TYPE_ FKS - Entity type discriminator for foreign keys
- ENTITY_
TYPE_ INDEXES - Entity type discriminator for indexes
- ENTITY_
TYPE_ PKS - Entity type discriminator for primary keys
- ENTITY_
TYPE_ TABLES - Entity type discriminator for tables
- ENTITY_
TYPE_ UNIQUES - Entity type discriminator for unique constraints
- ENTITY_
TYPE_ VIEWS - Entity type discriminator for views
Functions§
- name_
for_ check - Generate a default name for a check constraint
- name_
for_ fk - Generate a default name for a foreign key constraint
- name_
for_ index - Generate a default name for an index
- name_
for_ pk - Generate a default name for a primary key constraint
- name_
for_ unique - Generate a default name for a unique constraint