kw db
Contextual keyword — the effect list after the return type (§6.2)
The list of words: §1.4
Syntax
Effect = "io" | "net" | "db" | "time" | "rand" | Ident ;Grammar: App. A
Defined in
- 11.2 Database transaction — The body is executed in a transaction of the database db.
- 12.8 Built-in storage and tables — The storage is on every node of the journal role, replication is Raft per shard.
- 6.2 Effects — The set of effects is written after the return type, comma-separated
- 13.4 Authorisation and policies — The subject of a policy
- 5.9 Query expressions — Form: from x in source (where e)\* (order by e (asc|desc)?, …)?
- 1.4 Keywords — Reserved (cannot be used as names)
- 15.1 comptime — A comptime fn is executed only at compile time; comptime { …
- 18.2 Assertions and fixtures — assert expr is executed in all profiles, including prod (profiles switch off only contracts, §6.7, and the output of dbg, §2.2); on failure
Examples
atomic(db) {
db.insert(order)
db.update(User, uid) { ordersCount += 1 }
emit OrderEvents(OrderEvent.Created(order.id))
}policy Orders {
allow get(id) if caller.isUser(db.find(Order, id)?.userId)
allow list, recent if caller.has(role: .Support)
allow * if caller.service("billing")
deny delete unless caller.has(role: .Admin) && caller is .User(mfa: true, ..)
}
@public rpc health() -> Ok
@allow(role: .Admin) rpc purge() -> Ok
@internal rpc create(…) -> Order— 13.4 Authorisation and policies
Related diagnostics
atomic-db-effects, cross-shard-tx, query-not-sql, shard-count-clamped, table-schema, effects, data-rights, missing-policy, unknown-policy-target, comptime-error, not-comptime, fixture-yield