Skip to main content

Query Builder

Prism’s PrismQueryBuilder lets you construct SQL queries with a fluent Swift API. It’s not an ORM — it generates SQL strings and parameter arrays, giving you the safety of parameterized queries with the readability of a builder pattern.

Basic Queries

Select

Select All Columns
Select Specific Columns

Where Clauses

Filtering Results
Multiple .where() calls are joined with AND:
Combined Conditions

Ordering

Sort Results

Pagination

Limit and Offset

Write Operations

Insert a Row

Counting

Count Rows

Practical Example: Paginated API

Here’s how you’d build a paginated endpoint for a blog API:
Paginated Posts API
The query builder generates parameterized SQL under the hood, so all values are safely bound — no SQL injection risk.

When to Use Raw SQL

The query builder handles common cases well. For complex joins, subqueries, or database-specific features, drop down to raw SQL:
Complex Raw Query
Both approaches use the same actor-isolated PrismDatabase, so you can mix them freely.