MIT licensed by Travis Athougies
Maintained by [email protected]
This version can be pinned in stack with:beam-sqlite-0.6.0.0@sha256:33278f108803e17b8cb5c6ce9a0235266dc5033b99e88788ec88cb31e05dc271,3961

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 NULL constraints,
  • Primary keys,
  • User-created secondary indices (via PRAGMA index_list / PRAGMA index_info),
  • Foreign key constraints (via PRAGMA foreign_key_list), including ON DELETE / ON UPDATE actions.

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 = ON on each connection (or set it in your open hook) to enable it at runtime.

Changes

0.6.0.0

Added features

  • SqliteM now supports runUpdateReturningList via a MonadBeamUpdateReturning instance. The type is almost identical, but not quite, as the runUpdateReturningList function from previous releases. Instead, runUpdateReturningList has been renamed runSqliteUpdateReturningList.

  • Support for temporary tables.

  • getDbConstraints now discovers foreign key constraints via PRAGMA foreign_key_list, including ON DELETE / ON UPDATE actions.

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 INDEX and CREATE UNIQUE INDEX), including discovering user-created secondary indices via PRAGMA index_list / PRAGMA index_info.

0.5.6.0

Performance optimizations

  • insertReturning / deleteReturning / updateReturning now generate optimal SQL queries, minimizing the number of separate statements, by grouping similar statements in the presence of the DEFAULT keyword (#785).

0.5.5.0

Added features

  • runInsertReturningList now uses SQLite’s relatively new RETURNING clause.

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-sqlite to 2.3.27.
  • Updated the upper bound on time to include time-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 unix or windows package, which should enable (#738) beam-sqlite to 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
  • HasSqlEqualityCheck instance for Day

0.5.2.0

Bug fixes

  • Fix encoding for UTCTime

Addded features

  • IN (SELECT ...) syntax via inQuery_

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

  • MonadBase and MonadBaseControl instances for SqliteM

0.5.0.0

Interface changes

  • Removed instances for machine-dependent ambiguous integer types Int and Word

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 DECIMAL and DOUBLE PRECISION types
  • Fix bitLength, charLength_, and octectLength_ by emulating with CAST and LENGTH
  • Fix runInsertReturningList for 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 Database class

0.2.0.0

First split of sqlite backend from main beam package