glimr/db/gen/schema_parser

Schema Parser

Parses schema.gleam files to extract table definitions. This parser handles the list-based schema definition format:

table(name, [ id(), string(“name”), string(“bio”) |> nullable(), boolean(“is_active”) |> default(DefaultBool(True)), timestamps(), ])

Types

Represents a database column with its name, type, nullability, default value, and optional rename tracking.

pub type Column {
  Column(
    name: String,
    column_type: ColumnType,
    nullable: Bool,
    default: option.Option(DefaultValue),
    renamed_from: option.Option(String),
  )
}

Constructors

Represents the data type of a column. Maps to appropriate SQL types for each database driver.

pub type ColumnType {
  Id
  String
  Text
  Int
  BigInt
  Float
  Boolean
  Timestamp
  UnixTimestamp
  Date
  Json
  Uuid
  Foreign(String)
}

Constructors

  • Id
  • String
  • Text
  • Int
  • BigInt
  • Float
  • Boolean
  • Timestamp
  • UnixTimestamp
  • Date
  • Json
  • Uuid
  • Foreign(String)

Represents the default value for a column. Supports boolean, string, integer, float, current timestamp, current unix timestamp, and null defaults.

pub type DefaultValue {
  DefaultBool(Bool)
  DefaultString(String)
  DefaultInt(Int)
  DefaultFloat(Float)
  DefaultNow
  DefaultUnixNow
  DefaultAutoUuid
  DefaultNull
}

Constructors

  • DefaultBool(Bool)
  • DefaultString(String)
  • DefaultInt(Int)
  • DefaultFloat(Float)
  • DefaultNow
  • DefaultUnixNow
  • DefaultAutoUuid
  • DefaultNull

Represents a database table with a name and list of columns.

pub type Table {
  Table(name: String, columns: List(Column))
}

Constructors

  • Table(name: String, columns: List(Column))

Values

pub fn columns(table: Table) -> List(Column)

Get columns in definition order from a table.

pub fn parse(content: String) -> Result(Table, String)

Parse a schema.gleam file content into a Table structure. Extracts the table name from pub const name = "..." and parses the column definitions from the table(name, [...]) call.

Search Document