writeonce/tests/corpus/run/db-unique-catch/fixture.wo
shoney.arickathil 6f2f9b6f0a feat: secondary indexes + @unique trap (iteration 9, Task 4; wob v3)
- .wob v3: class records carry an index tail (flags bit0 = unique,
  col_cnt, columns) -- @table(index:[a,b]) entries plus one unique
  single-column entry per @unique field; loader validates columns in
  range and scalar/Text-kinded; emitter validates the declarations
  (unknown column, un-indexable kind => diagnostic)
- engine: db_index hash multimap per table, built from the class
  table at first touch, maintained ONLY inside wo_row_insert/
  wo_row_remove; unique checks re-compare actual column values (a
  hash is a hint); replay re-indexes via wo_row_raw_commit AFTER
  slots are filled, so recovered tables carry their indexes
- WO_T_UNIQUE = 10; a violating insert is un-applied whole (bitmap,
  hash, count, and the never-observable id reclaimed) and traps
  catchably -- the employee SEED-DUP pattern
- wo_row_insert gains err_kind so db.c maps UNIQUE/OOM/other to the
  right trap; test images and the runner's loader mirror speak v3
- fixtures: trap/db-unique-violation (code 10 exact) and
  run/db-unique-catch (catchable dup, composite index accepts
  duplicates, next id dense after a refusal)
- gates: oop-e2e 73/0, all 15 runtime suites, woc-test green,
  log-watcher 7/0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-15 12:57:32 +02:00

26 lines
807 B
Text

-- iteration 9 Task 4, the other half: the unique trap is catchable (the
-- employee sample's SEED-DUP pattern), a NON-unique @table composite index
-- accepts duplicates, and a distinct key inserts freely beside the taken
-- one. (Key release after delete joins the corpus with Task 5's delete.)
@table(name: "events", index: [kind, at])
class Event {
kind: Text
at: Int
}
class Account {
email: Text @unique
balance: Int
}
fn main() {
let a = insert Account { email: "a@x", balance: 100 }
print_int(a)
let dup = try insert Account { email: "a@x", balance: 200 } catch (e) nil
if dup == nil { print("DUP-REFUSED") }
insert Event { kind: "warn", at: 1 }
insert Event { kind: "warn", at: 1 }
print("EVENTS-OK")
let b = insert Account { email: "b@x", balance: 300 }
print_int(b)
}