marconi-core-1.2.0.0: Modular indexing for rewindable ledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Marconi.Core.Indexer.SQLiteIndexer

Description

On-disk indexer backed by a sqlite database.

See Marconi.Core for documentation.

Synopsis

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

Instances details
HasDatabasePath SQLiteIndexer # 
Instance details

Defined in Marconi.Core.Indexer.SQLiteAggregateQuery

MonadIO m => Closeable m SQLiteIndexer # 
Instance details

Defined in Marconi.Core.Indexer.SQLiteIndexer

Methods

close :: SQLiteIndexer event -> m () #

(MonadIO m, MonadError IndexerError m, ToRow (Point event)) => IsIndex m event SQLiteIndexer # 
Instance details

Defined in Marconi.Core.Indexer.SQLiteIndexer

Methods

index :: Timed (Point event) (Maybe event) -> SQLiteIndexer event -> m (SQLiteIndexer event) #

indexAll :: (Eq (Point event), Traversable f) => f (Timed (Point event) (Maybe event)) -> SQLiteIndexer event -> m (SQLiteIndexer event) #

indexAllDescending :: (Eq (Point event), Traversable f) => f (Timed (Point event) (Maybe event)) -> SQLiteIndexer event -> m (SQLiteIndexer event) #

rollback :: Point event -> SQLiteIndexer event -> m (SQLiteIndexer event) #

setLastStablePoint :: Point event -> SQLiteIndexer event -> m (SQLiteIndexer event) #

Monad m => IsSync m event SQLiteIndexer # 
Instance details

Defined in Marconi.Core.Indexer.SQLiteIndexer

Methods

lastStablePoint :: SQLiteIndexer event -> m (Point event) #

lastSyncPoint :: SQLiteIndexer event -> m (Point event) #

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.

newtype GetLastStablePointQuery #

A newtype to get the last stable point from an indexer.

Constructors

GetLastStablePointQuery 

Fields

mkSqliteIndexer #

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 param out of a Timed

-> [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.

mkSingleInsertSqliteIndexer #

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 param out of a Timed

-> 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

querySQLiteIndexerWith #

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

  • planExtractor :: Timed (Point event) event -> [a]

    How to transform the event into a type that can be handle by the database

  • planInsert :: Query

    The insert statement for the extracted data

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

  • tableName :: String

    the table to rollback

  • pointName :: String

    The name of the point field in the table

  • pointExtractor :: point -> Maybe a

    How we transform the data to the point field. Returning Nothing essentially means that we delete all information from the database. Returning 'Just a' means that we will delete all rows with a point higher than point.

Reexport from SQLite

class ToRow a where #

Minimal complete definition

Nothing

Methods

toRow :: a -> [SQLData] #

Instances

Instances details
ToRow () 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: () -> [SQLData] #

ToField a => ToRow (Only a) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: Only a -> [SQLData] #

ToField a => ToRow [a] 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: [a] -> [SQLData] #

(ToRow a, ToRow b) => ToRow (a :. b) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a :. b) -> [SQLData] #

(ToField a, ToField b) => ToRow (a, b) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b) -> [SQLData] #

(ToField a, ToField b, ToField c) => ToRow (a, b, c) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c) -> [SQLData] #

(ToField a, ToField b, ToField c, ToField d) => ToRow (a, b, c, d) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d) -> [SQLData] #

(ToField a, ToField b, ToField c, ToField d, ToField e) => ToRow (a, b, c, d, e) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e) -> [SQLData] #

(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f) => ToRow (a, b, c, d, e, f) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e, f) -> [SQLData] #

(ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g) => ToRow (a, b, c, d, e, f, g) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e, f, g) -> [SQLData] #

(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) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e, f, g, h) -> [SQLData] #

(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) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e, f, g, h, i) -> [SQLData] #

(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) 
Instance details

Defined in Database.SQLite.Simple.ToRow

Methods

toRow :: (a, b, c, d, e, f, g, h, i, j) -> [SQLData] #

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