1.8 KiB
1.8 KiB
SQLite Database Support
Overview
Add SQLite database support to Sis using the sqlite-simple library. On
startup, the server opens a SQLite database (creating the file if it doesn't
exist), enables WAL mode and foreign keys, and makes the connection available.
No tables are created yet — that comes in a later task.
Architecture
New dependency
sqlite-simpleadded topackage.yaml.
New module: Sis.Database
Exposes one function:
openDatabase :: FilePath -> IO Connection
Behavior:
- Opens (or creates) the SQLite database file at the given path.
- Enables WAL journal mode (
PRAGMA journal_mode=WAL). - Enables foreign keys (
PRAGMA foreign_keys=ON). - Returns the
Connection.
No tables are created in this task. The file will contain only the empty SQLite schema.
Server wiring
- New CLI option
--db-pathinapp/Main.hswith default valuedata/sis.db. mainopens the database connection viaSis.Database.openDatabasebefore starting the Warp server.- The connection is not yet passed into the Orb app — that wiring happens when the first table and routes are added in subsequent tasks.
Data flow
startup → parseOptions → openDatabase (creates file, sets pragmas)
→ start Warp server (connection held, unused for now)
Error handling
- If
openDatabasefails (e.g., unwritable path, disk full), the exception propagates and the server fails to start. This is correct — the server cannot function without its database.
Testing
- The existing
spectest suite does not require changes since there are no new routes or business logic. - Integration-level tests for database operations will be added when tables and queries are introduced in subsequent tasks.