Vex · Query DSL

Sort (sort)

sort is an ordered list of { field, dir } entries that compiles to ORDER BY. The first entry is the primary sort key, and each later entry breaks the ties left by the entries before it. dir is asc or desc.

Query
{
  from: ['bookings'],
  fields: ['bookings.id', 'bookings.seats'],
  sort: [
    { field: 'bookings.seats', dir: 'desc' },
    { field: 'bookings.id', dir: 'asc' },
  ],
}
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
)
SQL
SELECT b1.id AS "id", b1.seats AS "seats"
FROM bookings AS b1
ORDER BY b1.seats DESC, b1.id ASC
LIMIT 100
Output matches the expected value

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