Skip to main content
PocketBase uses SQLite as its database engine and provides a powerful query builder for database operations.

Database instances

DB()

Get the main database builder (automatically routes queries):
The DB() method automatically routes:
  • SELECT queries → Concurrent pool (for parallel reads)
  • INSERT/UPDATE/DELETE → Nonconcurrent pool (serialized writes)

ConcurrentDB()

Get the concurrent database instance for read operations:

NonconcurrentDB()

Get the nonconcurrent database instance for write operations:

Query builder basics

PocketBase uses the dbx package for query building:

SELECT queries

WHERE clauses

ORDER BY

LIMIT and OFFSET

JOINs

Executing queries

All()

Fetch all matching rows:

One()

Fetch a single row:

Row()

Scan a single row into variables:

Rows()

Scan multiple rows:

Execute()

Execute a statement without fetching results:

INSERT operations

Single row insert

Bulk insert

UPDATE operations

Update with conditions

DELETE operations

Delete with conditions

Transactions

RunInTransaction()

Execute multiple operations in a transaction:
Transactions automatically rollback if the function returns an error, and commit if it returns nil.

Nested transactions

Raw SQL

NewQuery()

Execute raw SQL queries:

With results

Table operations

HasTable()

Check if a table exists:

TableColumns()

Get all column names:

TableInfo()

Get detailed table information:

TableIndexes()

Get table indexes:

Vacuum

Reclaim unused disk space:

Model queries

ModelQuery()

Create a preconfigured query for a model:

Best practices

Always use parameterized queries

Handle errors properly