ormlette/ir/ir

This is an intermediate representation (IR) for the schema definition to convert it to a SQL CREATE TABLE statement. The IR is a data structure that represents the schema in a way that is easy to convert to SQL.

Types

Ir type for a column constraint, such as a PRIMARY KEY, FOREIGN KEY, UNIQUE, etc.

pub type ColumnConstraint {
  PrimaryKey
  Nullable
  Unique
  ForeignKey(
    references_table: TableIR,
    references_column: String,
    on_delete: Option(String),
    on_update: Option(String),
  )
}

Constructors

  • PrimaryKey
  • Nullable
  • Unique
  • ForeignKey(
      references_table: TableIR,
      references_column: String,
      on_delete: Option(String),
      on_update: Option(String),
    )

This is the IR type for a column.

pub type ColumnIR {
  ColumnIR(
    name: String,
    type_: create.ColumnType,
    constraints: List(ColumnConstraint),
    default: Option(dynamic.Dynamic),
  )
}

Constructors

  • ColumnIR(
      name: String,
      type_: create.ColumnType,
      constraints: List(ColumnConstraint),
      default: Option(dynamic.Dynamic),
    )

The IR type for a table It contains the table name and a list of columns (Basically the same as the create.Table type)

pub type TableIR {
  TableIR(name: String, columns: List(ColumnIR))
}

Constructors

  • TableIR(name: String, columns: List(ColumnIR))

Functions

pub fn to_ir(table: Table) -> TableIR

This function converts a create.Table to a TableIR

Search Document