cquill/introspection

Types

Foreign key referential action

pub type ForeignKeyAction {
  NoAction
  Restrict
  Cascade
  SetNull
  SetDefault
}

Constructors

  • NoAction
  • Restrict
  • Cascade
  • SetNull
  • SetDefault

A check constraint

pub type IntrospectedCheck {
  IntrospectedCheck(
    constraint_name: String,
    check_clause: String,
  )
}

Constructors

  • IntrospectedCheck(constraint_name: String, check_clause: String)

    Arguments

    constraint_name

    Constraint name

    check_clause

    Check expression (SQL)

A database column with metadata

pub type IntrospectedColumn {
  IntrospectedColumn(
    name: String,
    position: Int,
    data_type: String,
    udt_name: String,
    is_nullable: Bool,
    default: option.Option(String),
    max_length: option.Option(Int),
    numeric_precision: option.Option(Int),
    numeric_scale: option.Option(Int),
  )
}

Constructors

  • IntrospectedColumn(
      name: String,
      position: Int,
      data_type: String,
      udt_name: String,
      is_nullable: Bool,
      default: option.Option(String),
      max_length: option.Option(Int),
      numeric_precision: option.Option(Int),
      numeric_scale: option.Option(Int),
    )

    Arguments

    name

    Column name

    position

    Ordinal position (1-based)

    data_type

    SQL data type (e.g., “integer”, “character varying”)

    udt_name

    Underlying type name (useful for custom types/enums)

    is_nullable

    Whether the column allows NULL values

    default

    Default value expression (if any)

    max_length

    Maximum character length (for string types)

    numeric_precision

    Numeric precision (for numeric types)

    numeric_scale

    Numeric scale (for numeric types)

A database enum type

pub type IntrospectedEnum {
  IntrospectedEnum(name: String, values: List(String))
}

Constructors

  • IntrospectedEnum(name: String, values: List(String))

    Arguments

    name

    Enum type name

    values

    Enum values in order

A foreign key relationship

pub type IntrospectedForeignKey {
  IntrospectedForeignKey(
    column_name: String,
    foreign_table: String,
    foreign_column: String,
    on_update: ForeignKeyAction,
    on_delete: ForeignKeyAction,
  )
}

Constructors

  • IntrospectedForeignKey(
      column_name: String,
      foreign_table: String,
      foreign_column: String,
      on_update: ForeignKeyAction,
      on_delete: ForeignKeyAction,
    )

    Arguments

    column_name

    Column name in this table

    foreign_table

    Referenced table name

    foreign_column

    Referenced column name

    on_update

    ON UPDATE action

    on_delete

    ON DELETE action

Complete introspected database schema

pub type IntrospectedSchema {
  IntrospectedSchema(
    tables: List(IntrospectedTable),
    enums: List(IntrospectedEnum),
  )
}

Constructors

A database table with its complete structure

pub type IntrospectedTable {
  IntrospectedTable(
    name: String,
    columns: List(IntrospectedColumn),
    primary_key: List(String),
    foreign_keys: List(IntrospectedForeignKey),
    unique_constraints: List(IntrospectedUnique),
    check_constraints: List(IntrospectedCheck),
  )
}

Constructors

  • IntrospectedTable(
      name: String,
      columns: List(IntrospectedColumn),
      primary_key: List(String),
      foreign_keys: List(IntrospectedForeignKey),
      unique_constraints: List(IntrospectedUnique),
      check_constraints: List(IntrospectedCheck),
    )

    Arguments

    name

    Table name

    columns

    Columns in ordinal position order

    primary_key

    Primary key column names (supports composite keys)

    foreign_keys

    Foreign key relationships

    unique_constraints

    Unique constraints

    check_constraints

    Check constraints

A unique constraint

pub type IntrospectedUnique {
  IntrospectedUnique(
    constraint_name: String,
    columns: List(String),
  )
}

Constructors

  • IntrospectedUnique(
      constraint_name: String,
      columns: List(String),
    )

    Arguments

    constraint_name

    Constraint name

    columns

    Columns covered by this constraint (supports composite)

Raw check constraint data from introspection query

pub type RawCheckRow {
  RawCheckRow(
    table_name: String,
    constraint_name: String,
    check_clause: String,
  )
}

Constructors

  • RawCheckRow(
      table_name: String,
      constraint_name: String,
      check_clause: String,
    )

Raw column data from introspection query

pub type RawColumnRow {
  RawColumnRow(
    table_name: String,
    column_name: String,
    ordinal_position: Int,
    data_type: String,
    udt_name: String,
    is_nullable: String,
    column_default: option.Option(String),
    character_maximum_length: option.Option(Int),
    numeric_precision: option.Option(Int),
    numeric_scale: option.Option(Int),
  )
}

Constructors

  • RawColumnRow(
      table_name: String,
      column_name: String,
      ordinal_position: Int,
      data_type: String,
      udt_name: String,
      is_nullable: String,
      column_default: option.Option(String),
      character_maximum_length: option.Option(Int),
      numeric_precision: option.Option(Int),
      numeric_scale: option.Option(Int),
    )

Raw enum data from introspection query

pub type RawEnumRow {
  RawEnumRow(
    enum_name: String,
    enum_value: String,
    enum_sort_order: Float,
  )
}

Constructors

  • RawEnumRow(
      enum_name: String,
      enum_value: String,
      enum_sort_order: Float,
    )

Raw foreign key data from introspection query

pub type RawForeignKeyRow {
  RawForeignKeyRow(
    table_name: String,
    column_name: String,
    foreign_table_name: String,
    foreign_column_name: String,
    update_rule: String,
    delete_rule: String,
  )
}

Constructors

  • RawForeignKeyRow(
      table_name: String,
      column_name: String,
      foreign_table_name: String,
      foreign_column_name: String,
      update_rule: String,
      delete_rule: String,
    )

Raw primary key data from introspection query

pub type RawPrimaryKeyRow {
  RawPrimaryKeyRow(
    table_name: String,
    column_name: String,
    ordinal_position: Int,
  )
}

Constructors

  • RawPrimaryKeyRow(
      table_name: String,
      column_name: String,
      ordinal_position: Int,
    )

Raw unique constraint data from introspection query

pub type RawUniqueRow {
  RawUniqueRow(
    table_name: String,
    constraint_name: String,
    column_name: String,
  )
}

Constructors

  • RawUniqueRow(
      table_name: String,
      constraint_name: String,
      column_name: String,
    )

Values

pub fn build_check(row: RawCheckRow) -> IntrospectedCheck

Build IntrospectedCheck from raw row data

pub fn build_column(row: RawColumnRow) -> IntrospectedColumn

Build IntrospectedColumn from raw row data

pub fn build_foreign_key(
  row: RawForeignKeyRow,
) -> IntrospectedForeignKey

Build IntrospectedForeignKey from raw row data

pub fn build_schema(
  column_rows: List(RawColumnRow),
  pk_rows: List(RawPrimaryKeyRow),
  fk_rows: List(RawForeignKeyRow),
  unique_rows: List(RawUniqueRow),
  check_rows: List(RawCheckRow),
  enum_rows: List(RawEnumRow),
) -> IntrospectedSchema

Build a complete IntrospectedSchema from raw query results

pub fn check_constraints_query() -> String

Get SQL query for check constraints Parameter $1 is the schema name

pub fn column_names(table: IntrospectedTable) -> List(String)

Get all column names in a table

pub fn columns_query() -> String

Get SQL query for table and column information Parameter $1 is the schema name (e.g., “public”)

pub fn empty_schema() -> IntrospectedSchema

Create an empty introspected schema

pub fn empty_table(name: String) -> IntrospectedTable

Create an empty introspected table

pub fn enums_query() -> String

Get SQL query for enum types Parameter $1 is the schema name

pub fn find_column(
  table: IntrospectedTable,
  name: String,
) -> option.Option(IntrospectedColumn)

Find a column by name in a table

pub fn find_enum(
  schema: IntrospectedSchema,
  name: String,
) -> option.Option(IntrospectedEnum)

Find an enum by name in the schema

pub fn find_table(
  schema: IntrospectedSchema,
  name: String,
) -> option.Option(IntrospectedTable)

Find a table by name in the schema

pub fn foreign_keys_query() -> String

Get SQL query for foreign keys Parameter $1 is the schema name

pub fn get_column_foreign_key(
  table: IntrospectedTable,
  column_name: String,
) -> option.Option(IntrospectedForeignKey)

Get the foreign key for a column (if any)

pub fn get_foreign_keys(
  table: IntrospectedTable,
) -> List(IntrospectedForeignKey)

Get all foreign keys from a table

pub fn gleam_type_for_postgres(
  data_type: String,
  udt_name: String,
  is_nullable: Bool,
) -> String

Map Postgres data type to a Gleam-friendly type name

pub fn has_composite_primary_key(
  table: IntrospectedTable,
) -> Bool

Check if a table has a composite primary key

pub fn has_foreign_key(
  table: IntrospectedTable,
  column_name: String,
) -> Bool

Check if a column has a foreign key constraint

pub fn has_primary_key(table: IntrospectedTable) -> Bool

Check if a table has a primary key

pub fn is_primary_key_column(
  table: IntrospectedTable,
  column_name: String,
) -> Bool

Check if a column is part of the primary key

pub fn parse_fk_action(action: String) -> ForeignKeyAction

Parse foreign key action from SQL string

pub fn parse_nullable(value: String) -> Bool

Parse is_nullable string to boolean

pub fn pascal_case(input: String) -> String

Convert snake_case to PascalCase

pub fn primary_keys_query() -> String

Get SQL query for primary keys Parameter $1 is the schema name

pub fn table_names(schema: IntrospectedSchema) -> List(String)

Get all table names in the schema

pub fn tables_referencing(
  schema: IntrospectedSchema,
  table_name: String,
) -> List(IntrospectedTable)

Get all tables that reference a given table via foreign key

pub fn unique_constraints_query() -> String

Get SQL query for unique constraints Parameter $1 is the schema name

Search Document