Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Store

This Northwind-style example models a purchase order as a header plus explicit line items. OrderItem represents the many-to-many relationship between purchase orders and products while keeping mutations executable with the current single-link syntax.

type Customer {
  required unique email: str
  required name: str
  required tier: str
}

type Product {
  required unique sku: str
  required name: str
  required price: float64
  required active: bool
}

type PurchaseOrder {
  required unique order_no: str
  required status: str
  required ordered_at: datetime
  required link customer: Customer
}

type OrderItem {
  required quantity: int64
  required unit_price: float64
  required link purchase: PurchaseOrder
  required link product: Product
}

Create data

cargo run -p gelite-cli -- schema apply examples/store.geli --database store.db
cargo run -p gelite-cli -- repl --database store.db

Insert a customer and two products, keeping their generated IDs:

insert Customer {
  email := "[email protected]",
  name := "Margo Hosho",
  tier := "gold"
}
insert Product {
  sku := "CASE-NOTEBOOK",
  name := "Detective Notebook",
  price := 12.5,
  active := true
}
insert Product {
  sku := "OWL-PIN",
  name := "Owl Enamel Pin",
  price := 8.0,
  active := true
}

Create the purchase order and its items in one interactive transaction. Replace the placeholders with generated IDs and the ID printed by the purchase order insert:

start transaction
insert PurchaseOrder {
  order_no := "TRIAL-0001",
  status := "paid",
  ordered_at := "2026-08-03T10:00:00Z",
  customer := "<margo-id>"
}
insert OrderItem {
  quantity := 2,
  unit_price := 12.5,
  purchase := "<purchase-order-id>",
  product := "<notebook-id>"
}
insert OrderItem {
  quantity := 1,
  unit_price := 8.0,
  purchase := "<purchase-order-id>",
  product := "<pin-id>"
}
commit

Query line totals

select OrderItem {
  line_total := f64(.quantity) * .unit_price,
  product: {
    sku,
    name
  },
  purchase: {
    order_no,
    status,
    customer: {
      name,
      tier
    }
  }
}
filter .purchase.status in ["paid", "shipped"]
  and .product.active = true
order by f64(.quantity) * .unit_price desc

Computed projections are executed by SQLite. Their current REPL column labels are generated implementation aliases rather than the logical output names.