cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.DB.Sqlite

Description

An implementation of the DBLayer which uses Persistent and SQLite.

Synopsis

Documentation

newtype SqliteContext Source #

SqliteContext is a function to execute queries.

Constructors

SqliteContext

Fields

newSqliteContext :: Tracer IO DBLog -> ConnectionPool -> [ ManualMigration ] -> Migration -> IO ( Either MigrationError SqliteContext ) Source #

Sets up query logging and timing, runs schema migrations if necessary and provide a safe SqliteContext for interacting with the database.

data ForeignKeysSetting Source #

Specifies whether or not foreign key constraints are enabled, equivalent to the Sqlite foreign_keys setting.

When foreign key constraints are enabled , the database will enforce referential integrity, and cascading deletes are enabled.

When foreign keys constraints are disabled , the database will not enforce referential integrity, and cascading deletes are disabled.

See the following resource for more information: https://www.sqlite.org/foreignkeys.html#fk_enable

Constructors

ForeignKeysEnabled

Foreign key constraints are enabled .

ForeignKeysDisabled

Foreign key constraints are disabled .

ConnectionPool

Helpers

chunkSize :: Int Source #

Maximum number of variables allowed in a single SQL statement

See also dbChunked .

dbChunked :: forall record b. PersistEntity record => ([record] -> SqlPersistT IO b) -> [record] -> SqlPersistT IO () Source #

Convert a single DB "updateMany" (or similar) query into multiple updateMany queries with smaller lists of values.

This is to prevent too many variables appearing in the SQL statement. SQLITE_MAX_VARIABLE_NUMBER is 999 by default, and we will get a "too many SQL variables" exception if that is exceeded.

We choose a conservative value chunkSize << 999 because there can be multiple variables per row updated.

dbChunkedFor :: forall record a b. PersistEntity record => ([a] -> SqlPersistT IO b) -> [a] -> SqlPersistT IO () Source #

Like dbChunked , but generalized for the case where the input list is not the same type as the record.

dbChunked' :: forall record b. PersistEntity record => ([( Key record, record)] -> SqlPersistT IO b) -> [( Key record, record)] -> SqlPersistT IO () Source #

Like dbChunked , but allows bundling elements with a Key . Useful when used with repsertMany .

handleConstraint :: MonadUnliftIO m => e -> m a -> m ( Either e a) Source #

Run an action, and convert any Sqlite constraints exception into the given error result. No other exceptions are handled.

Manual Migration

newtype ManualMigration Source #

Encapsulates a manual migration action (or sequence of actions) to be performed immediately after an SQL connection is initiated.

newtype MigrationError Source #

Error type for when migrations go wrong after opening a database.

Instances

Instances details
Eq MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

Show MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

Generic MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

ToJSON MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

Exception MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

type Rep MigrationError Source #
Instance details

Defined in Cardano.DB.Sqlite

type Rep MigrationError = D1 (' MetaData "MigrationError" "Cardano.DB.Sqlite" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "MigrationError" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getMigrationErrorMessage") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Text )))

Logging

data DBLog Source #