Configuration
SQLite.Configuration defines how a database is opened and how it behaves at runtime. It controls fundamental SQLite settings such as foreign key enforcement, journaling mode, busy handling, read-only mode, and reader concurrency. It also provides a hook to initialize schema and perform one-time database setup.
SQLite is a global API in Scripting and does not require an import. In production code, wrap database operations in try / catch.
Type Definition
Properties
foreignKeysEnabled
Enables or disables SQLite foreign key constraints.
When enabled, SQLite enforces REFERENCES constraints and applies ON DELETE / ON UPDATE actions.
Practical guidance:
- Enable this when your schema uses foreign keys and you rely on referential integrity.
- If disabled, foreign key declarations may exist in schema but are not enforced.
readonly
Opens the database in read-only mode.
Practical guidance:
- Use for analytics, reporting, or safe viewing of data.
- Any write attempt (DDL/DML) will fail.
label
An optional identifier used to describe the connection instance (for debugging, logging, diagnostics, or internal labeling).
busyMode
Controls what happens when the database is busy (locked by another connection/transaction).
Allowed values:
"immediateError": fail immediately when the database is busyDurationInSeconds: wait for the specified number of seconds before failing
Practical guidance:
- For UI-sensitive scripts or strict latency control, consider
"immediateError". - For normal workloads with occasional contention, use a small duration (for example
1–3seconds).
journalMode
Controls SQLite journaling behavior.
"default": platform/default journaling behavior"wal": write-ahead logging, typically better for concurrency
Practical guidance:
walis usually recommended for concurrent read access and better throughput.- Use
defaultif you want the system default behavior or need maximum compatibility.
maximumReaderCount
Sets the maximum number of concurrent reader connections (primarily relevant for DatabasePool).
Practical guidance:
- Increase for read-heavy workloads where parallel queries improve performance.
- Keep moderate to avoid excessive resource usage.
Methods
prepareDatabase(setup)
Registers a setup callback executed when preparing the database connection. This is the recommended place to:
- Create tables and indexes
- Perform schema migrations
- Set up deterministic initial state
Important notes:
- Keep this callback deterministic and fast.
- Avoid putting large data imports here; treat it as schema/setup logic.
- If you need migrations, prefer checking
db.schemaVersion()(or your own versioning approach) and applying incremental updates.
Recommended Patterns
Basic Configuration Template
Using a Configuration with Queue vs Pool
Common Mistakes
- Not enabling foreign keys when using
referencesin table definitions. - Setting an excessively large
maximumReaderCount(may increase memory/file descriptor usage). - Using
"immediateError"busy mode in workflows that regularly contend on the same database. - Performing heavy data operations inside
prepareDatabase(should focus on schema).
