Vex · API

collectQueryContext

collectQueryContext(query, schema) returns the $context keys a query requires before it can execute, each with the column its value is compared with and that column’s type. The result is derived from the query and the schema, so no separate declaration is written.

Query
{
  from: ['bookings'],
  fields: ['bookings.id', 'bookings.seats'],
  filter: {
    and: [
      { eq: ['bookings.show_night', { $context: 'night' }] },
      { gte: ['bookings.seats', { $context: 'least' }] },
    ],
  },
}
Table
CREATE TABLE bookings (
  id text PRIMARY KEY,
  show_night text NOT NULL REFERENCES shows(night),
  member_id text NOT NULL REFERENCES members(id),
  seats integer NOT NULL
)
Required context
{
  night: { type: 'string', column: 'bookings.show_night' },
  least: { type: 'number', column: 'bookings.seats' },
}
Output matches the expected value

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