Skip to main content
PocketBase provides powerful database query capabilities through the $dbx namespace and query builder methods.

Query builder

The query builder allows you to construct complex SQL queries using a fluent interface.

Basic queries

Filtering

Multiple conditions

OR conditions

Expressions

The $dbx namespace provides several expression builders:

Hash expression

Custom expression

IN expression

LIKE expression

BETWEEN expression

EXISTS expression

Logical operators

Sorting and pagination

Order by

Limit and offset

Counting records

Aggregations

Using raw SQL

Group by

Joins

Inner join

Left join

Transactions

Transactions ensure that multiple database operations either all succeed or all fail together.

Basic transaction

Error handling

Raw SQL queries

SELECT queries

Multiple results

INSERT queries

UPDATE queries

DELETE queries

Performance tips

Use indexes

Limit result sets

Always use limit() when you don’t need all records:

Use select fields

When using raw SQL, only select the fields you need:

Example: Search with pagination