Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
An implementation of the DBLayer which uses Persistent and SQLite.
Synopsis
-
newtype
SqliteContext
=
SqliteContext
{
- runQuery :: forall a. SqlPersistT IO a -> IO a
- newSqliteContext :: Tracer IO DBLog -> ConnectionPool -> [ ManualMigration ] -> Migration -> IO ( Either MigrationError SqliteContext )
- newInMemorySqliteContext :: Tracer IO DBLog -> [ ManualMigration ] -> Migration -> ForeignKeysSetting -> IO ( IO (), SqliteContext )
- data ForeignKeysSetting
- type ConnectionPool = Pool ( SqlBackend , Connection )
- withConnectionPool :: Tracer IO DBLog -> FilePath -> ( ConnectionPool -> IO a) -> IO a
- chunkSize :: Int
- dbChunked :: forall record b. PersistEntity record => ([record] -> SqlPersistT IO b) -> [record] -> SqlPersistT IO ()
- dbChunkedFor :: forall record a b. PersistEntity record => ([a] -> SqlPersistT IO b) -> [a] -> SqlPersistT IO ()
- dbChunked' :: forall record b. PersistEntity record => ([( Key record, record)] -> SqlPersistT IO b) -> [( Key record, record)] -> SqlPersistT IO ()
- handleConstraint :: MonadUnliftIO m => e -> m a -> m ( Either e a)
-
newtype
ManualMigration
=
ManualMigration
{
- executeManualMigration :: Connection -> IO ()
- newtype MigrationError = MigrationError { }
-
data
DBField
where
- DBField :: forall record typ. PersistEntity record => EntityField record typ -> DBField
- tableName :: DBField -> Text
- fieldName :: DBField -> Text
- fieldType :: DBField -> Text
-
data
DBLog
- = MsgMigrations ( Either MigrationError Int )
- | MsgQuery Text Severity
- | MsgRun BracketLog
- | MsgCloseSingleConnection FilePath
- | MsgStartConnectionPool FilePath
- | MsgStopConnectionPool FilePath
- | MsgDatabaseReset
- | MsgIsAlreadyClosed Text
- | MsgStatementAlreadyFinalized Text
- | MsgManualMigrationNeeded DBField Text
- | MsgExpectedMigration DBLog
- | MsgManualMigrationNotNeeded DBField
- | MsgUpdatingForeignKeysSetting ForeignKeysSetting
- | MsgRetryOnBusy Int RetryLog
Documentation
newtype SqliteContext Source #
SqliteContext
is a function to execute queries.
SqliteContext | |
|
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.
newInMemorySqliteContext :: Tracer IO DBLog -> [ ManualMigration ] -> Migration -> ForeignKeysSetting -> IO ( IO (), SqliteContext ) Source #
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
ForeignKeysEnabled |
Foreign key constraints are enabled . |
ForeignKeysDisabled |
Foreign key constraints are disabled . |
Instances
ConnectionPool
type ConnectionPool = Pool ( SqlBackend , Connection ) Source #
withConnectionPool :: Tracer IO DBLog -> FilePath -> ( ConnectionPool -> IO a) -> IO a Source #
Helpers
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 #
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
DBField :: forall record typ. PersistEntity record => EntityField record typ -> DBField |
Logging
Instances
Eq DBLog Source # | |
Show DBLog Source # | |
Generic DBLog Source # | |
ToJSON DBLog Source # | |
ToText DBLog Source # | |
HasPrivacyAnnotation DBLog Source # | |
Defined in Cardano.DB.Sqlite getPrivacyAnnotation :: DBLog -> PrivacyAnnotation |
|
HasSeverityAnnotation DBLog Source # | |
Defined in Cardano.DB.Sqlite getSeverityAnnotation :: DBLog -> Severity |
|
type Rep DBLog Source # | |
Defined in Cardano.DB.Sqlite |