Skip to main content

Database Overview

Prism ships with a built-in SQLite database layer that talks directly to the C API through sqlite3.h. There’s no ORM abstraction tax — you get raw performance with a clean Swift interface, all wrapped in an actor for safe concurrent access.
Prism uses the system SQLite that ships with macOS and Linux. No additional installation needed.

Why SQLite?

SQLite is the most deployed database in the world. For many server applications — APIs, microservices, internal tools — it’s the right choice:
  • Zero configuration — no separate database process to manage
  • Single-file storage — easy backups, easy deployment
  • Incredible read performance — faster than client-server databases for most workloads
  • ACID compliant — full transaction support
SQLite handles thousands of concurrent reads and hundreds of writes per second. For most APIs, that’s more than enough. When you outgrow it, Prism’s PrismDatabase protocol makes it straightforward to swap backends.

Creating a Database

Basic Setup
For testing, use an in-memory database:
In-Memory Database

Creating Tables

Creating a Users Table

Basic CRUD Operations

Insert a Row

Parameter Binding

Always use parameterized queries to prevent SQL injection:
Safe Parameter Binding
Never interpolate user input directly into SQL strings. Always use ? placeholders and pass values through the parameters array.

Transactions

Group multiple operations into an atomic transaction:
Transaction Example
If any statement fails, the entire transaction rolls back automatically.

Query Results

PrismRow gives you typed access to column values:
Working with Rows

Using with the Server

Database in Route Handlers

Query Builder

Build queries fluently without writing raw SQL

Models

Map database rows to Swift structs automatically

Migrations

Version your database schema with up/down migrations

Connection Pool

Handle concurrent requests with pooled connections