Module ddl

Module ddl 

Source
Expand description

SQLite DDL (Data Definition Language) entity types

This module provides two complementary types for each DDL entity:

  • *Def types - Const-friendly definitions using only Copy types (&'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§

CheckConstraint
Runtime check constraint entity
CheckConstraintDef
Const-friendly check constraint definition
Column
Runtime column entity for serde serialization.
ColumnDef
Const-friendly column definition for compile-time schema definitions.
ForeignKey
Runtime foreign key constraint entity
ForeignKeyDef
Const-friendly foreign key definition
Generated
Generated column configuration (runtime)
GeneratedDef
Generated column configuration (const-friendly)
Index
Runtime index entity for serde serialization
IndexColumn
Runtime index column entity for serde serialization
IndexColumnDef
Const-friendly index column specification
IndexDef
Const-friendly index definition
PrimaryKey
Runtime primary key constraint entity
PrimaryKeyDef
Const-friendly primary key definition
Table
Runtime table entity for serde serialization.
TableDef
Const-friendly table definition for compile-time schema definitions.
UniqueConstraint
Runtime unique constraint entity
UniqueConstraintDef
Const-friendly unique constraint definition
View
Runtime view entity
ViewDef
Const-friendly view definition

Enums§

GeneratedType
Generated column type
IndexOrigin
Index origin - how the index was created
ReferentialAction
Foreign key referential action
SqliteEntity
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