helix_ir.ddl

helix_ir.ddl — DDL generation for multiple SQL dialects.

helix_ir.ddl.compile_ddl(schema_or_plan: Any, dialect: str = 'duckdb', options: DDLOptions | None = None) DDLScript[source]

Compile a Schema or NormalizationPlan to a DDL script.

Parameters:
  • schema_or_plan – A Schema instance or NormalizationPlan instance.

  • dialect – Target SQL dialect name.

  • options – DDL generation options.

Returns:

A DDLScript with all CREATE TABLE statements.

helix_ir.ddl.compile_migration(schema_diff: SchemaDiff, dialect: str = 'duckdb', table_name: str | None = None, options: DDLOptions | None = None, skip_breaking: bool = False) DDLScript[source]

Compile a SchemaDiff into ALTER TABLE migration statements.

Parameters:
  • schema_diff – The diff between old and new schema.

  • dialect – Target SQL dialect.

  • table_name – Table name to alter. Defaults to schema_diff.new_name.

  • options – DDL options.

  • skip_breaking – If True, skip breaking changes (dangerous!).

Returns:

A DDLScript with ALTER TABLE statements.

class helix_ir.ddl.DDLOptions(if_not_exists: bool = True, include_comments: bool = True, primary_key: str | None = '__id', schema_prefix: str | None = None, extra_options: dict[str, ~typing.Any]=<factory>)[source]

Bases: object

Options controlling DDL generation.

if_not_exists: bool = True
include_comments: bool = True
primary_key: str | None = '__id'
schema_prefix: str | None = None
extra_options: dict[str, Any]
class helix_ir.ddl.DDLScript(dialect: str, statements: list[str] = <factory>)[source]

Bases: object

A compiled DDL script.

dialect: str
statements: list[str]
add(stmt: str) None[source]
to_sql() str[source]

Return all statements joined by double newlines.

helix_ir.ddl.get_dialect(name: str) BaseDialect[source]

Return a dialect instance by name.