Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Marconi.Core.Indexer.SQLiteIndexer
Description
On-disk indexer backed by a sqlite database.
See Marconi.Core for documentation.
Synopsis
- data SQLiteIndexer event = SQLiteIndexer SQLiteDBLocation Connection (Pool Connection) [[SQLInsertPlan event]] [SQLRollbackPlan (Point event)] SetLastStablePointQuery (Point event) (Point event)
- data SQLiteDBLocation
- data ExpectedPersistentDB = ExpectedPersistentDB
- inMemoryDB :: SQLiteDBLocation
- parseDBLocation :: String -> SQLiteDBLocation
- databasePath :: forall event. Lens' (SQLiteIndexer event) SQLiteDBLocation
- writeConnection :: forall event. Lens' (SQLiteIndexer event) Connection
- readConnectionPool :: forall event. Lens' (SQLiteIndexer event) (Pool Connection)
- insertPlan :: forall event. Lens' (SQLiteIndexer event) [[SQLInsertPlan event]]
- newtype InsertPointQuery = InsertPointQuery {
- getInsertPointQuery :: Query
- newtype SetLastStablePointQuery = SetLastStablePointQuery {
- getSetLastStablePointQuery :: Query
- newtype GetLastStablePointQuery = GetLastStablePointQuery {
- getLastStablePointQuery :: Query
- mkSqliteIndexer :: forall event m. (MonadIO m, MonadError IndexerError m, HasGenesis (Point event), FromRow (Point event), ToRow (Point event), Ord (Point event)) => SQLiteDBLocation -> [Query] -> [[SQLInsertPlan event]] -> [SQLRollbackPlan (Point event)] -> SetLastStablePointQuery -> GetLastStablePointQuery -> m (SQLiteIndexer event)
- mkSingleInsertSqliteIndexer :: forall m event param. (MonadIO m, MonadError IndexerError m, HasGenesis (Point event), FromRow (Point event), ToRow (Point event), ToRow param, Ord (Point event)) => SQLiteDBLocation -> (Timed (Point event) event -> param) -> Query -> Query -> SQLRollbackPlan (Point event) -> SetLastStablePointQuery -> GetLastStablePointQuery -> m (SQLiteIndexer event)
- querySQLiteIndexerWith :: (MonadIO m, MonadError (QueryError query) m, Ord (Point event), FromRow r) => (Point event -> query -> [NamedParam]) -> (query -> Query) -> (query -> [r] -> Result query) -> Point event -> query -> SQLiteIndexer event -> m (Result query)
- queryLatestSQLiteIndexerWith :: MonadIO m => FromRow r => (query -> [NamedParam]) -> (query -> Query) -> (query -> [r] -> Result query) -> query -> SQLiteIndexer event -> m (Result query)
- querySyncedOnlySQLiteIndexerWith :: MonadIO m => MonadError (QueryError query) m => Ord (Point event) => FromRow r => (Point event -> query -> [NamedParam]) -> (query -> Query) -> (query -> [r] -> Result query) -> Point event -> query -> SQLiteIndexer event -> m (Result query)
- handleSQLErrors :: IO a -> IO (Either IndexerError a)
- dbLastSync :: forall event. Lens' (SQLiteIndexer event) (Point event)
- data SQLInsertPlan event = forall a.ToRow a => SQLInsertPlan {
- planExtractor :: Timed (Point event) event -> [a]
- planInsert :: Query
- data SQLRollbackPlan point = forall a.ToField a => SQLRollbackPlan {}
- class ToRow a where
- toRow :: a -> [SQLData]
- readOnlyConnection :: MonadIO io => SQLiteDBLocation -> io Connection
- readWriteConnection :: (MonadIO io, MonadError IndexerError io) => SQLiteDBLocation -> io Connection
Documentation
data SQLiteIndexer event #
Provide the minimal elements required to use a SQLite database to back an indexer.
Constructors
SQLiteIndexer SQLiteDBLocation Connection (Pool Connection) [[SQLInsertPlan event]] [SQLRollbackPlan (Point event)] SetLastStablePointQuery (Point event) (Point event) |
Instances
data SQLiteDBLocation #
data ExpectedPersistentDB #
Constructors
ExpectedPersistentDB |
Instances
databasePath :: forall event. Lens' (SQLiteIndexer event) SQLiteDBLocation #
writeConnection :: forall event. Lens' (SQLiteIndexer event) Connection #
readConnectionPool :: forall event. Lens' (SQLiteIndexer event) (Pool Connection) #
insertPlan :: forall event. Lens' (SQLiteIndexer event) [[SQLInsertPlan event]] #
newtype InsertPointQuery #
Constructors
InsertPointQuery | |
Fields
|
newtype SetLastStablePointQuery #
A newtype to set the last stable point of an indexer.
Constructors
SetLastStablePointQuery | |
Fields
|
newtype GetLastStablePointQuery #
A newtype to get the last stable point from an indexer.
Constructors
GetLastStablePointQuery | |
Fields
|
Arguments
:: forall event m. (MonadIO m, MonadError IndexerError m, HasGenesis (Point event), FromRow (Point event), ToRow (Point event), Ord (Point event)) | |
=> SQLiteDBLocation | |
-> [Query] | creation statement |
-> [[SQLInsertPlan event]] | extract |
-> [SQLRollbackPlan (Point event)] | the rollbackQuery |
-> SetLastStablePointQuery | The SQL query to set the last stable point of the indexer. |
-> GetLastStablePointQuery | The SQL query to fetch the last stable point from the indexer. |
-> m (SQLiteIndexer event) |
Start a new indexer or resume an existing SQLite indexer
The main difference with SQLiteIndexer
is that we set dbLastSync
thanks to the provided query.
It helps resuming an existing indexer.
Arguments
:: forall m event param. (MonadIO m, MonadError IndexerError m, HasGenesis (Point event), FromRow (Point event), ToRow (Point event), ToRow param, Ord (Point event)) | |
=> SQLiteDBLocation | |
-> (Timed (Point event) event -> param) | extract |
-> Query | the creation query |
-> Query | the insert query |
-> SQLRollbackPlan (Point event) | the rollback query |
-> SetLastStablePointQuery | The SQL query to set the last stable point of the indexer. |
-> GetLastStablePointQuery | The SQL query to fetch the last stable point from the indexer. |
-> m (SQLiteIndexer event) |
A smart constructor for indexer that want to map an event to a single table. We just have to set the type family of `InsertRecord event` to `[param]` and then to provide the expected parameters.
It is monomorphic restriction of mkSqliteIndexer
Arguments
:: (MonadIO m, MonadError (QueryError query) m, Ord (Point event), FromRow r) | |
=> (Point event -> query -> [NamedParam]) | A preprocessing of the query, to obtain SQL parameters |
-> (query -> Query) | The sqlite query statement |
-> (query -> [r] -> Result query) | Post processing of the result, to obtain the final result |
-> Point event | |
-> query | |
-> SQLiteIndexer event | |
-> m (Result query) |
A helper for the definition of the Queryable
typeclass for SQLiteIndexer
The helper just remove a bit of the boilerplate needed to transform data to query the database.
It doesn't contain any logic, except a check for AheadOfLastSync
error,
in which case it throws the AheadOfLastSync
exception with a partial result.
If you don't want to query the database on a partial result,
use querySyncedOnlySQLiteIndexerWith
It doesn't filter the result based on the given data point.
queryLatestSQLiteIndexerWith #
Arguments
:: MonadIO m | |
=> FromRow r | |
=> (query -> [NamedParam]) | A preprocessing of the query, to obtain SQL parameters |
-> (query -> Query) | The sqlite query statement |
-> (query -> [r] -> Result query) | Post processing of the result, to obtain the final result |
-> query | |
-> SQLiteIndexer event | |
-> m (Result query) |
A helper for the definition of queryLatest
in the Queryable
typeclass
for SQLiteIndexer
.
The helper just remove a bit of the boilerplate needed to transform data to query the database. It also assumes that the SQL query will deal with the latest part (we don't use a side query to access the latest sync point).
querySyncedOnlySQLiteIndexerWith #
Arguments
:: MonadIO m | |
=> MonadError (QueryError query) m | |
=> Ord (Point event) | |
=> FromRow r | |
=> (Point event -> query -> [NamedParam]) | A preprocessing of the query, to obtain SQL parameters |
-> (query -> Query) | The sqlite query statement |
-> (query -> [r] -> Result query) | Post processing of the result, to obtain the final result |
-> Point event | |
-> query | |
-> SQLiteIndexer event | |
-> m (Result query) |
A helper for the definition of the Queryable
typeclass for SQLiteIndexer
.
The helper just remove a bit of the boilerplate needed to transform data to query the database.
It doesn't contain any logic, except a check for AheadOfLastSync
error,
in which case it throws the AheadOfLastSync
without any result attached.
It doesn't filter the result based on the given data point.
handleSQLErrors :: IO a -> IO (Either IndexerError a) #
Map SQLite errors to an indexer error
dbLastSync :: forall event. Lens' (SQLiteIndexer event) (Point event) #
data SQLInsertPlan event #
A SQLInsertPlan
provides a piece information about how an event should be inserted in the database
Constructors
forall a.ToRow a => SQLInsertPlan | |
Fields
|
data SQLRollbackPlan point #
A SQLRollbackPlan
provides a piece of information on how to perform a rollback on the data
inserted in the database.
Constructors
forall a.ToField a => SQLRollbackPlan | |
Fields |
Reexport from SQLite
Minimal complete definition
Nothing
Instances
ToRow () | |
Defined in Database.SQLite.Simple.ToRow | |
ToField a => ToRow (Only a) | |
Defined in Database.SQLite.Simple.ToRow | |
ToField a => ToRow [a] | |
Defined in Database.SQLite.Simple.ToRow | |
(ToRow a, ToRow b) => ToRow (a :. b) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b) => ToRow (a, b) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c) => ToRow (a, b, c) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d) => ToRow (a, b, c, d) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e) => ToRow (a, b, c, d, e) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f) => ToRow (a, b, c, d, e, f) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g) => ToRow (a, b, c, d, e, f, g) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g, ToField h) => ToRow (a, b, c, d, e, f, g, h) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g, ToField h, ToField i) => ToRow (a, b, c, d, e, f, g, h, i) | |
Defined in Database.SQLite.Simple.ToRow | |
(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g, ToField h, ToField i, ToField j) => ToRow (a, b, c, d, e, f, g, h, i, j) | |
Defined in Database.SQLite.Simple.ToRow |
Concurrent and read only connection for sqlite-simple connection
readOnlyConnection :: MonadIO io => SQLiteDBLocation -> io Connection #
Create an SQL connection with ReadOnly permission and concurrent connections
readWriteConnection :: (MonadIO io, MonadError IndexerError io) => SQLiteDBLocation -> io Connection #
Create an SQL connection with ReadWrite permission and concurrent connections