Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- interpretQStoreDb :: forall f q d e r. ResultShape d (f d) => Member (DbTable d !! e) r => TableSchema d -> QuerySchema q d -> InterpreterFor (QStore f q d !! e) r
- interpretQStoreXa :: forall f err i d r. ResultShape d (f d) => Members [Scoped ConnectionSource (DbTable d !! err), Log, Embed IO] r => TableSchema d -> QuerySchema i d -> InterpreterFor (Scoped Connection (QStore f i d !! err) !! err) r
- interpretQStores :: forall f err q d r. ResultShape d (f d) => Members [Scoped ConnectionSource (DbTable d !! err), DbTable d !! err, Log, Embed IO] r => TableSchema d -> QuerySchema q d -> InterpretersFor [QStore f q d !! err, Scoped Connection (QStore f q d !! err) !! err] r
- interpretStoreDb :: forall i d e r. Member (StoreTable i d !! e) r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpreterFor (Store i d !! e) r
- interpretStoreXa :: forall err i d r. Members [Scoped ConnectionSource (DbTable (Uid i d) !! err), Log, Embed IO] r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpreterFor (Scoped Connection (Store i d !! err) !! err) r
- interpretStores :: forall err i d r. Members [Scoped ConnectionSource (DbTable (Uid i d) !! err), StoreTable i d !! err, Log, Embed IO] r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpretersFor [Store i d !! err, Scoped Connection (Store i d !! err) !! err] r
- interpretQuery :: forall result query proj table r. ResultShape proj result => Member (DbTable table !! DbError) r => Projection proj table -> QuerySchema query table -> InterpreterFor (Query query result !! DbError) r
- interpretQueryDd :: forall result query proj table r. MkTableSchema proj => MkTableSchema table => CheckedProjection proj table => CheckQuery query table => ResultShape (DdType proj) result => Member (DbTable (DdType table) !! DbError) r => Dd table -> Dd proj -> Dd query -> InterpreterFor (Query (DdType query) result !! DbError) r
- data DbConnectionPool :: Effect
- data Database :: Effect
- type Databases = Scoped ConnectionSource (Database !! DbError)
- data DbTable a :: Effect
- type StoreTable i a = DbTable (Uid i a)
- data Transaction res :: Effect
- type Transactions res = Scoped_ (Transaction res)
- abort :: forall res r a. Member (Transaction res) r => Sem r a
- interpretDbConnectionPool :: Members [Log, Resource, Embed IO, Final IO] r => DbConfig -> Maybe Int -> Maybe Int -> InterpreterFor (DbConnectionPool !! DbConnectionError) r
- interpretDbConnectionPoolSingle :: Member (Embed IO) r => DbConfig -> InterpreterFor (DbConnectionPool !! DbConnectionError) r
- interpretDatabase :: forall t d r. Members [DbConnectionPool !! DbConnectionError, Time t d, Resource, Log, Mask, Race, Embed IO, Final IO] r => InterpretersFor [Database !! DbError, Scoped ConnectionSource (Database !! DbError)] r
- interpretDatabases :: forall t d r. Members [DbConnectionPool !! DbConnectionError, AtomicState ConnectionsState] r => Members [Time t d, Log, Resource, Mask, Race, Embed IO, Final IO] r => InterpreterFor (Scoped ConnectionSource (Database !! DbError)) r
- interpretHasql :: Members [Time t d, Log, Mask, Resource, Race, Embed IO, Final IO] r => DbConfig -> Maybe Int -> Maybe Int -> InterpretersFor HasqlStack r
- interpretTablesMigrations :: forall d migs p r. CustomSemMigrations r migs => Members [Scoped p (Database !! DbError), Database !! DbError, Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpretersFor [Scoped p (DbTable d !! DbError), DbTable d !! DbError] r
- interpretTableMigrations :: forall d migs r. CustomSemMigrations r migs => Members [Database !! DbError, Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpreterFor (DbTable d !! DbError) r
- interpretTableMigrationsScoped :: CustomSemMigrations r migs => Members [Scoped p (Database !! DbError), Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpreterFor (Scoped p (DbTable d !! DbError)) r
- interpretTables :: Members [Scoped p (Database !! DbError), Database !! DbError, Log, Embed IO] r => TableSchema d -> InterpretersFor [Scoped p (DbTable d !! DbError), DbTable d !! DbError] r
- interpretTable :: forall d r. Members [Database !! DbError, Log, Embed IO] r => TableSchema d -> InterpreterFor (DbTable d !! DbError) r
- interpretTableView :: Member (DbTable table !! DbError) r => ProjectionWitness view table -> InterpreterFor (DbTable view !! DbError) r
- interpretTableViewDd :: CheckedProjection view table => Member (DbTable (DdType table) !! DbError) r => Dd table -> Dd view -> InterpreterFor (DbTable (DdType view) !! DbError) r
- queryVia :: (q1 -> Sem (Stop DbError ': r) q2) -> (r2 -> Sem (Stop DbError ': r) r1) -> Sem ((Query q1 r1 !! DbError) ': r) a -> Sem ((Query q2 r2 !! DbError) ': r) a
- mapQuery :: (q1 -> Sem (Stop DbError ': r) q2) -> Sem ((Query q1 result !! DbError) ': r) a -> Sem ((Query q2 result !! DbError) ': r) a
- interpretAtomicStateDb :: Members [DbTable d !! e, Error InitDbError, Mask, Resource, Race, Embed IO] r => TableSchema d -> Sem r d -> InterpreterFor (AtomicState d !! e) r
- interpretAtomicStatesDb :: Members [Error InitDbError, Mask, Resource, Race, Embed IO] r => Members [Scoped ConnectionSource (DbTable d !! err), DbTable d !! err, Log, Embed IO] r => TableSchema d -> Sem r d -> InterpretersFor [AtomicState d !! err, Scoped Connection (AtomicState d !! err) !! err] r
- interpretReaderDb :: forall d e r. Member (DbTable d !! e) r => TableSchema d -> Sem r d -> InterpreterFor (Reader d !! e) r
Introduction
This library provides Hasql-specific interpreters for the effects in Polysemy.Db
Hasql interpreters for Polysemy.Db
interpretQStoreDb :: forall f q d e r. ResultShape d (f d) => Member (DbTable d !! e) r => TableSchema d -> QuerySchema q d -> InterpreterFor (QStore f q d !! e) r Source #
interpretQStoreXa :: forall f err i d r. ResultShape d (f d) => Members [Scoped ConnectionSource (DbTable d !! err), Log, Embed IO] r => TableSchema d -> QuerySchema i d -> InterpreterFor (Scoped Connection (QStore f i d !! err) !! err) r Source #
interpretQStores :: forall f err q d r. ResultShape d (f d) => Members [Scoped ConnectionSource (DbTable d !! err), DbTable d !! err, Log, Embed IO] r => TableSchema d -> QuerySchema q d -> InterpretersFor [QStore f q d !! err, Scoped Connection (QStore f q d !! err) !! err] r Source #
interpretStoreDb :: forall i d e r. Member (StoreTable i d !! e) r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpreterFor (Store i d !! e) r Source #
interpretStoreXa :: forall err i d r. Members [Scoped ConnectionSource (DbTable (Uid i d) !! err), Log, Embed IO] r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpreterFor (Scoped Connection (Store i d !! err) !! err) r Source #
interpretStores :: forall err i d r. Members [Scoped ConnectionSource (DbTable (Uid i d) !! err), StoreTable i d !! err, Log, Embed IO] r => TableSchema (Uid i d) -> QuerySchema i (Uid i d) -> InterpretersFor [Store i d !! err, Scoped Connection (Store i d !! err) !! err] r Source #
interpretQuery :: forall result query proj table r. ResultShape proj result => Member (DbTable table !! DbError) r => Projection proj table -> QuerySchema query table -> InterpreterFor (Query query result !! DbError) r Source #
interpretQueryDd :: forall result query proj table r. MkTableSchema proj => MkTableSchema table => CheckedProjection proj table => CheckQuery query table => ResultShape (DdType proj) result => Member (DbTable (DdType table) !! DbError) r => Dd table -> Dd proj -> Dd query -> InterpreterFor (Query (DdType query) result !! DbError) r Source #
Database effects
data DbConnectionPool :: Effect Source #
data Database :: Effect Source #
This effect provides the capability to execute Statement
s.
Additionally, it exposes managed access to the raw Connection
resource and automatic table initialization as
higher-order actions.
With the minimal stack, an SQL query can be executed in two fashions. One is to use automatically derived codecs:
prog :: Member Database r => Sem r () prog = do user :: Maybe User <- Database.sql () "select * from users where id = 1" user :: [User] <- Database.sql ("guest", True) "select * from users where name = $1 and locked = $2"
The other works by providing an explicit Statement
:
statement :: Statement Text User statement = ... prog :: Member Database r => Sem r () prog = do user <- Database.runStatement "guest" statement
For documentation on the individual constructors, see the module page.
type StoreTable i a = DbTable (Uid i a) Source #
data Transaction res :: Effect Source #
type Transactions res = Scoped_ (Transaction res) Source #
Database interpeters
interpretDbConnectionPool :: Members [Log, Resource, Embed IO, Final IO] r => DbConfig -> Maybe Int -> Maybe Int -> InterpreterFor (DbConnectionPool !! DbConnectionError) r Source #
interpretDbConnectionPoolSingle :: Member (Embed IO) r => DbConfig -> InterpreterFor (DbConnectionPool !! DbConnectionError) r Source #
interpretDatabase :: forall t d r. Members [DbConnectionPool !! DbConnectionError, Time t d, Resource, Log, Mask, Race, Embed IO, Final IO] r => InterpretersFor [Database !! DbError, Scoped ConnectionSource (Database !! DbError)] r Source #
interpretDatabases :: forall t d r. Members [DbConnectionPool !! DbConnectionError, AtomicState ConnectionsState] r => Members [Time t d, Log, Resource, Mask, Race, Embed IO, Final IO] r => InterpreterFor (Scoped ConnectionSource (Database !! DbError)) r Source #
interpretHasql :: Members [Time t d, Log, Mask, Resource, Race, Embed IO, Final IO] r => DbConfig -> Maybe Int -> Maybe Int -> InterpretersFor HasqlStack r Source #
interpretTablesMigrations :: forall d migs p r. CustomSemMigrations r migs => Members [Scoped p (Database !! DbError), Database !! DbError, Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpretersFor [Scoped p (DbTable d !! DbError), DbTable d !! DbError] r Source #
interpretTableMigrations :: forall d migs r. CustomSemMigrations r migs => Members [Database !! DbError, Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpreterFor (DbTable d !! DbError) r Source #
interpretTableMigrationsScoped :: CustomSemMigrations r migs => Members [Scoped p (Database !! DbError), Log, Embed IO] r => TableSchema d -> SemMigrations r migs -> InterpreterFor (Scoped p (DbTable d !! DbError)) r Source #
interpretTables :: Members [Scoped p (Database !! DbError), Database !! DbError, Log, Embed IO] r => TableSchema d -> InterpretersFor [Scoped p (DbTable d !! DbError), DbTable d !! DbError] r Source #
interpretTable :: forall d r. Members [Database !! DbError, Log, Embed IO] r => TableSchema d -> InterpreterFor (DbTable d !! DbError) r Source #
interpretTableView :: Member (DbTable table !! DbError) r => ProjectionWitness view table -> InterpreterFor (DbTable view !! DbError) r Source #
interpretTableViewDd :: CheckedProjection view table => Member (DbTable (DdType table) !! DbError) r => Dd table -> Dd view -> InterpreterFor (DbTable (DdType view) !! DbError) r Source #
Misc combinators
queryVia :: (q1 -> Sem (Stop DbError ': r) q2) -> (r2 -> Sem (Stop DbError ': r) r1) -> Sem ((Query q1 r1 !! DbError) ': r) a -> Sem ((Query q2 r2 !! DbError) ': r) a Source #
mapQuery :: (q1 -> Sem (Stop DbError ': r) q2) -> Sem ((Query q1 result !! DbError) ': r) a -> Sem ((Query q2 result !! DbError) ': r) a Source #
Misc
interpretAtomicStateDb :: Members [DbTable d !! e, Error InitDbError, Mask, Resource, Race, Embed IO] r => TableSchema d -> Sem r d -> InterpreterFor (AtomicState d !! e) r Source #
Interpret AtomicState
as a singleton table.
Given an action that produces an initial value, every state action reads the value from the database and writes it back.
interpretAtomicStatesDb :: Members [Error InitDbError, Mask, Resource, Race, Embed IO] r => Members [Scoped ConnectionSource (DbTable d !! err), DbTable d !! err, Log, Embed IO] r => TableSchema d -> Sem r d -> InterpretersFor [AtomicState d !! err, Scoped Connection (AtomicState d !! err) !! err] r Source #
interpretReaderDb :: forall d e r. Member (DbTable d !! e) r => TableSchema d -> Sem r d -> InterpreterFor (Reader d !! e) r Source #
Interpret Reader
as a singleton table.
Given an initial value, every state action reads the value from the database, potentially writing it on first access.