← all modules

Std.Db.Schema

Std.Db.Schema
  Std.Db.Schema — a typed, dialect-aware schema builder (Layer 3 Sky source).

Types
  type alias Column
  type alias Index
  type alias Table

Values
  autoIncrement : Column -> Column
      Auto-increment this integer key (AUTOINCREMENT on SQLite / SERIAL on
  bigInt : String -> Column
      64-bit integer — INTEGER on SQLite, BIGINT on Postgres. Use this for
  blob : String -> Column
      Binary — BLOB on SQLite, BYTEA on Postgres.
  bool : String -> Column
      Boolean — rendered as **BOOLEAN on Postgres** and **INTEGER 0/1 on SQLite**
  createSchema : Db -> List Table -> Task Error ()
      Create a whole schema (a list of tables, in order).
  createTable : Db -> Table -> Task Error ()
      Create the table (+ its indexes) using the DIALECT-CORRECT DDL for the
  defaultBool : Bool -> Column -> Column
      Boolean default: `bool "active" |> defaultBool True`.
  defaultInt : Int -> Column -> Column
      Integer/real default: `int "n" |> defaultInt 0`.
  defaultNow : Column -> Column
      Current-timestamp default — `datetime('now')` on SQLite, `now()` on Postgres.
  defaultText : String -> Column -> Column
      Text default (quoted + escaped per dialect): `text "role" |> defaultText "customer"`.
  id : String -> Column
      A TEXT primary key — the common Sky pattern (app-generated ids / UUIDs).
  int : String -> Column
      32-bit integer (INTEGER on both). Use `bigInt` for large / millisecond values.
  json : String -> Column
      JSON, stored as TEXT on BOTH backends (read consistency; native JSONB is a
  notNull : Column -> Column
      Mark this column NOT NULL: `text "email" |> notNull`.
  primaryKey : Column -> Column
      Mark this column the table's PRIMARY KEY: `text "id" |> primaryKey`.
  real : String -> Column
      Floating point — REAL on SQLite, DOUBLE PRECISION on Postgres.
  references : String -> String -> Column -> Column
      Foreign key: `text "order_id" |> references "orders" "id"`.
  serial : String -> Column
      An auto-incrementing integer primary key — INTEGER PRIMARY KEY AUTOINCREMENT
  table : String -> List Column -> Table
      Define a table from a name and its columns: `table "users" [ id "id", ... ]`.
  text : String -> Column
      TEXT on both backends.
  timestamp : String -> Column
      A millisecond-epoch timestamp — INTEGER on SQLite, BIGINT on Postgres.
  toProject : List Table -> Store.Project
      Bridge these explicit `Schema.Table` definitions into a `Store.Project`, so
  unique : Column -> Column
      Add a UNIQUE constraint on this column: `text "slug" |> notNull |> unique`.
  withIndex : String -> List String -> Table -> Table
      Add a (non-unique) index over one or more columns:
  withUniqueIndex : String -> List String -> Table -> Table
      Add a UNIQUE index over one or more columns: `... |> withUniqueIndex