Vex · Scope policies

Scope values as bound parameters

A scope value compiles to a bound parameter of kind scope, alongside the context parameters of the request. Example: $1 is night, supplied by the caller; $2 is memberId, the signed-in user, which comes from the server and never from the request. The SQL text is identical for Grace and for Linus; only the parameter values differ.

Query
{
  from: ['bookings', 'shows'],
  fields: ['shows.title', 'bookings.seats'],
  filter: { eq: ['bookings.show_night', { $context: 'night' }] },
}
SQL, member policy
SELECT s1.title AS "title", b1.seats AS "seats"
FROM bookings AS b1
JOIN shows AS s1 ON b1.show_night = s1.night
WHERE (b1.show_night = $1 AND b1.member_id = $2)
LIMIT 100
Parameters
[
  { key: 'night', kind: 'context', type: 'string' },
  { key: 'memberId', kind: 'scope', type: 'string' },
]
Parameter values, by user
{
  grace: ['2026-10-24', 'grace'],
  linus: ['2026-10-24', 'linus'],
}
Output matches the expected value

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