beam-sqlite
Beam driver for SQLite
https://haskell-beam.github.io/beam/user-guide/backends/beam-sqlite/
| LTS Haskell 24.38: | 0.5.7.0 |
| Stackage Nightly 2026-04-29: | 0.7.0.0 |
| Latest on Hackage: | 0.7.0.0 |
beam-sqlite-0.7.0.0@sha256:1b6eb32c36c62460d6fc0497f6b157623e9e499985076cf8bb32c3e89e430538,3956Module documentation for 0.7.0.0
beam-sqlite: Beam backend for the SQLite embedded database
beam-sqlite is a beam backend for
the SQLite embedded database.
SQLite is mostly standards compliant, but there are a few cases that beam-sqlite cannot handle. These cases may result in run-time errors. For more information, see the documentation. Due to SQLite’s embedded nature, there are currently no plans to get rid of these. However, proposals and PRs to fix these corner cases are welcome, where appropriate.
Migration support
beam-sqlite supports schema introspection and verification via
Database.Beam.Sqlite.Migrate, including:
- Tables, columns, and their types,
NOT NULLconstraints,- Primary keys,
- User-created secondary indices (via
PRAGMA index_list/PRAGMA index_info), - Foreign key constraints (via
PRAGMA foreign_key_list), includingON DELETE/ON UPDATEactions.
Declaring foreign keys
Use addTableForeignKey from beam-migrate to declare a foreign key on a
checked table entity:
let db = defaultMigratableDbSettings `withDbModification`
(dbModification @_ @Sqlite)
{ _orders =
addTableForeignKey (_customers db)
(\t -> selectorColumnName _order_customer_id t NE.:| [])
primaryKeyColumns
ForeignKeyNoAction -- ON UPDATE NO ACTION (default)
ForeignKeyActionCascade -- ON DELETE CASCADE
}
Note: SQLite disables foreign key enforcement by default. Issue
PRAGMA foreign_keys = ONon each connection (or set it in your open hook) to enable it at runtime.
Changes
0.7.0.0
Interface changes
- The legacy module-level
runInsertReturningListandrunDeleteReturningListfunctions exported fromDatabase.Beam.Sqlite(which run aSqliteInsertReturning/SqliteDeleteReturningvalue) have been renamed torunSqliteInsertReturningListandrunSqliteDeleteReturningListto avoid clashing with theMonadBeamInsertReturning/MonadBeamDeleteReturningclass methods of the same name. This matches the existingrunSqliteUpdateReturningList. BeamSqlBackendHasSerialforSqliteis now polymorphic over the column type via a newIsSqliteSerialIntegerTypeconstraint, sogenericSerialcan be used for any supported integer width rather than onlyInt(#534).
Added features
- Added a
MonadBeamDeleteReturning Sqlite SqliteMinstance, allowingrunDeleteReturningList(andrunDeleteReturningListWith) to be used directly againstSqliteMwithout going through the legacySqliteDeleteReturningbuilder. - Implemented the new
runInsertReturningListWith/runUpdateReturningListWith/runDeleteReturningListWithclass methods onSqliteM, allowing callers to project a subset of columns from the affected rows of anINSERT/UPDATE/DELETE ... RETURNING(#801). - Implemented
weekFieldfor SQLiteEXTRACT, mapped tostrftime('%W', ...), in support of the new backend-agnosticweek_extract field frombeam-core.
Updated dependencies
- Bumped the lower bound on
beam-coreto0.11.
0.6.0.0
Added features
-
SqliteMnow supportsrunUpdateReturningListvia aMonadBeamUpdateReturninginstance. The type is almost identical, but not quite, as therunUpdateReturningListfunction from previous releases. Instead,runUpdateReturningListhas been renamedrunSqliteUpdateReturningList. -
Support for temporary tables.
-
getDbConstraintsnow discovers foreign key constraints viaPRAGMA foreign_key_list, includingON DELETE/ON UPDATEactions.
Bug fixes
- The SQLite migration framework no longer incorrectly concludes a migration
would lose data due to the presence of internal
sqlite_*tables.
0.5.7.0
Added features
- Add support for creating secondary indices (
CREATE INDEXandCREATE UNIQUE INDEX), including discovering user-created secondary indices viaPRAGMA index_list/PRAGMA index_info.
0.5.6.0
Performance optimizations
insertReturning/deleteReturning/updateReturningnow generate optimal SQL queries, minimizing the number of separate statements, by grouping similar statements in the presence of theDEFAULTkeyword (#785).
0.5.5.0
Added features
runInsertReturningListnow uses SQLite’s relatively newRETURNINGclause.
Bux fixes
- Fixed an issue where values inserted with conflicts did not return then when using
runInsertReturningList(#774)
Updated dependencies
- Updated the lower bound of
direct-sqliteto2.3.27. - Updated the upper bound on
timeto includetime-1.14.
0.5.4.1
Dependencies
- Ensure that beam-sqlite uses sqlite-3.24+, which is the minimum supported version (#589).
0.5.4.0
Added features
- Removed the reliance on either the
unixorwindowspackage, which should enable (#738)beam-sqliteto be buildable on a wider variety of platforms.
0.5.3.1
Added features
- Replaced use of deprecated functions.
0.5.3.0
Added features
- Loosen some version bounds
HasSqlEqualityCheckinstance forDay
0.5.2.0
Bug fixes
- Fix encoding for
UTCTime
Addded features
IN (SELECT ...)syntax viainQuery_
0.5.1.2
Added features
- Aeson 2.0 support
0.5.1.1
Added features
- GHC 9.2 and 9.0 support
Bug fixes
- Support inserting default values for all columns (except with upsert)
0.5.1.0
Added features
MonadBaseandMonadBaseControlinstances forSqliteM
0.5.0.0
Interface changes
- Removed instances for machine-dependent ambiguous integer types
IntandWord
Added features
- Support for
in_on row values - Upsert support using
HasInsertOnConflict - Fix build on Android and OpenBSD
Bug fixes
- Fix emitting and detection of
DECIMALandDOUBLE PRECISIONtypes - Fix
bitLength,charLength_, andoctectLength_by emulating withCASTandLENGTH - Fix
runInsertReturningListfor when the database column order and beam column order disagree.
0.4.0.0
0.3.2.0
Add Semigroup instances to prepare for GHC 8.4 and Stackage nightly
0.3.1.0
Add runBeamSqlite and runBeamSqliteDebug functions
0.3.0.0
- Re-introduce backend parameter to
Databaseclass
0.2.0.0
First split of sqlite backend from main beam package