The fluent builders compile a statement and run it through the connection. Each builder method on Surreal returns a builder object you configure with chained calls, then run with execute() or inspect with compile().
All builders extend QueryBuilder in the SurrealDB\SDK\Query namespace.
Shared methods
Every builder provides these methods.
| Method | Returns | Description |
|---|---|---|
execute() | mixed | Run the statement and return the first statement's result |
compile() | BoundQuery | Compile to SurrealQL and bindings without running |
json(bool $json = true) | static | Request JSON-compatible results |
Raw queries
run()
Execute raw SurrealQL with optional bindings. Returns one result per statement.
query()
Execute a pre-built BoundQuery. Returns one result per statement.
select()
Start a SELECT. Accepts a RecordId, Table, or string target.
create()
Start a CREATE. Accepts a RecordId, Table, or string target.
update() and upsert()
Start an UPDATE or UPSERT. update() modifies existing records; upsert() creates the record if it does not exist.
delete()
Start a DELETE. It defaults to RETURN BEFORE, so deleted records are returned.
insert()
Start an INSERT. Pass a target table and records, or records alone when each carries its own ID.
relate()
Start a RELATE, creating one or more graph edges.
call()
Invoke a SurrealQL or SurrealML function by name. run() already handles raw SurrealQL, so function invocation has its own method.
auth()
Compile to SELECT * FROM ONLY $auth, returning the authenticated record user.
Modifiers
Output
output() accepts the SurrealDB\SDK\Enum\Output enum: NONE, NULL_, DIFF, BEFORE, AFTER.
Where
where() accepts a SurrealQL string or a BoundQuery fragment. Use a BoundQuery to keep dynamic values parameterised.
Timeout
timeout() accepts a SurrealQL duration string such as 5s or 1m30s.
See also
Executing queries for the guide
Core classes for the
Surrealentry pointUtilities for
BoundQueryand theOutputenum