Surqlize builds a SELECT as a typed query object. You start it from a model, refine it with chained methods, and either compile it to a SurrealQL string or execute it through the SDK executor.
The closures receive a typed field set, so field names, conditions, and projections are checked against your model. You can also pass plain strings where you prefer.
Selecting fields
Pass a closure that returns the fields to select, or an array of field names. query() is shorthand for SELECT *.
Where clauses
A where() closure returns one predicate, or a list of predicates that are combined with AND.
Field helpers map to SurrealQL operators.
| Helper | Operator |
|---|---|
eq($value) | = |
notEq($value) | != |
gt($value) | > |
gte($value) | >= |
lt($value) | < |
lte($value) | <= |
includes($value) | INCLUDES |
contains($value) | CONTAINS |
like($value) | LIKE |
condition($operator, $value) | A custom operator |
Ordering
orderBy() accepts a field helper, or a field plus a direction.
Fetching links
fetch() resolves record links so related records are returned inline.
Pagination
page() sets a page and page size. limit() and start() give the same control directly.
Projections and aggregates
Combine projection helpers with groupBy() to aggregate.
The available helpers are Projection::count(), Projection::sum($field), Projection::mean($field), and Projection::raw($expression). Chain ->as('alias') to name the result.
Advanced SELECT clauses
Surqlize supports the wider set of SurrealQL SELECT clauses, compiled in the correct order.
Other clause helpers include withoutIndex(), groupAll(), and withoutFrom(). timeout() takes an amount and an optional unit (s by default).
Selecting values
selectValue() builds a SELECT VALUE query that returns scalar rows.
SELECT VALUE rows are scalars and cannot be hydrated with collectModels().
Executing a query
| Method | Result |
|---|---|
compile() | A literal SurrealQL string, for debugging and tests |
toBoundQuery() | An SDK BoundQuery with parameter-bound values |
collect() | A list of raw rows |
collectModels() | A list of hydrated models |
lazyModels() | A generator of hydrated models |
first() | The first scalar or model, depending on the query |
explainPlan() | The raw rows from an EXPLAIN query |
Note
Learn more
Mutations for create, update, and delete
Edges and graph for graph traversal in a select
Search, vector, and geometry for specialised field helpers