Database instances
DB()
Get the main database builder (automatically routes queries):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 thedbx 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.