The Wix JavaScript SDK provides query builder utility methods that let you construct filter, sort, and paging objects using a chainable syntax. You can pass the resulting query object directly to any SDK query method.
Each SDK package that supports querying exports the following utilities: QueryBuilder, Filter, and Sort.
SDK query methods accept queries written in the Wix API Query Language, a JSON-based format for filtering, sorting, and paging. While this format is flexible and consistent across all Wix APIs, building these objects can be difficult, especially for complex queries.
Query builder utilities offer the following benefits:
.withFilter() and .withSorting(), rather than writing JSON objects by hand.Each SDK package exports the following utilities alongside its query methods:
| Utility | Purpose |
|---|---|
Filter(fieldName) | Creates a filter condition for a specified field. Supports operators like .eq(), .ne(), .gt(), .gte(), .lt(), .lte(), .in(), .nin(), .exists(), .startsWith(), .isEmpty(), .hasAll(), and .hasSome(). |
Sort(fieldName) | Creates a sort condition for a specified field. Supports .asc() for ascending and .desc() for descending order. |
QueryBuilder() | Combines filters and sorts into a complete query object. Supports .withFilter(), .withSorting(), and .build(). |
The following examples query Bookings services for all services of type "COURSE", sorted by name in ascending order.
Query builder utilities are particularly useful when you need to construct queries based on conditions that aren't known until runtime. Instead of manually assembling a JSON filter object, you can compose filters and sorts programmatically.
For example, the following helper method builds a query for Bookings services where the filter and sort are optional and determined by the caller: