Vex · Scope policies

Column set by policy on write (set)

A set rule in a scope policy writes its column from a scope value on a write, overriding the value the request supplies. Example: the write binds member_id to the $context key member and the request passes linus; the member policy sets member_id from the scope value memberId, so the bound parameter is grace. The caller cannot choose the owner of the booking.

Write
{
  op: 'insert',
  table: 'bookings',
  values: {
    id: { $context: 'id' },
    show_night: { $context: 'night' },
    member_id: { $context: 'member' },
    seats: { $context: 'seats' },
  },
}
Context and scope
{
  context: {
    id: 'B-2047',
    night: '2026-10-25',
    member: 'linus',
    seats: 2,
  },
  scope: { memberId: 'grace' },
}
SQL
INSERT INTO bookings (id, show_night, member_id, seats)
VALUES ($1, $2, $3, $4)
RETURNING *
Parameter values
['B-2047', '2026-10-25', 'grace', 2]
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.