Safe Haskell | None |
---|---|
Language | Haskell2010 |
- runQuery :: Default QueryRunner columns haskells => Connection -> Query columns -> IO [haskells]
- runQueryFold :: Default QueryRunner columns haskells => Connection -> Query columns -> b -> (b -> haskells -> IO b) -> IO b
- queryRunnerColumn :: (Column a' -> Column a) -> (b -> b') -> QueryRunnerColumn a b -> QueryRunnerColumn a' b'
- runQueryExplicit :: QueryRunner columns haskells -> Connection -> Query columns -> IO [haskells]
- runQueryFoldExplicit :: QueryRunner columns haskells -> Connection -> Query columns -> b -> (b -> haskells -> IO b) -> IO b
- prepareQuery :: QueryRunner columns haskells -> Query columns -> (Maybe Query, RowParser haskells)
- data QueryRunner columns haskells
- data QueryRunnerColumn pgType haskellType
- class QueryRunnerColumnDefault pgType haskellType where
- fieldQueryRunnerColumn :: FromField haskell => QueryRunnerColumn pgType haskell
- fieldParserQueryRunnerColumn :: FieldParser haskell -> QueryRunnerColumn pgType haskell
Running Query
s
runQuery :: Default QueryRunner columns haskells => Connection -> Query columns -> IO [haskells] Source #
runQuery
's use of the Default
typeclass means that the
compiler will have trouble inferring types. It is strongly
recommended that you provide full type signatures when using
runQuery
.
Example type specialization:
runQuery :: Query (ColumnPGInt4
, ColumnPGText
) -> IO [(Int, String)]
Assuming the makeAdaptorAndInstance
splice has been run for the product type Foo
:
runQuery :: Query (Foo (ColumnPGInt4
) (ColumnPGText
) (ColumnPGBool
) -> IO [Foo Int String Bool]
Opaleye types are converted to Haskell types based on instances of
the QueryRunnerColumnDefault
typeclass.
runQueryFold :: Default QueryRunner columns haskells => Connection -> Query columns -> b -> (b -> haskells -> IO b) -> IO b Source #
runQueryFold
streams the results of a query incrementally and consumes
the results with a left fold.
This fold is not strict. The stream consumer is responsible for forcing the evaluation of its result to avoid space leaks.
Creating new QueryRunnerColumn
s
queryRunnerColumn :: (Column a' -> Column a) -> (b -> b') -> QueryRunnerColumn a b -> QueryRunnerColumn a' b' Source #
Use queryRunnerColumn
to make an instance to allow you to run queries on
your own datatypes. For example:
newtype Foo = Foo Int
instance QueryRunnerColumnDefault Foo Foo where
queryRunnerColumnDefault =
queryRunnerColumn (unsafeCoerceColumn
:: Column Foo -> Column PGInt4)
Foo
queryRunnerColumnDefault
Explicit versions
runQueryExplicit :: QueryRunner columns haskells -> Connection -> Query columns -> IO [haskells] Source #
runQueryFoldExplicit :: QueryRunner columns haskells -> Connection -> Query columns -> b -> (b -> haskells -> IO b) -> IO b Source #
Deprecated functions
prepareQuery :: QueryRunner columns haskells -> Query columns -> (Maybe Query, RowParser haskells) Source #
For internal use only. Do not use. Will be deprecated in version 0.6.
data QueryRunner columns haskells Source #
A QueryRunner
specifies how to convert Postgres values (columns
)
into Haskell values (haskells
). Most likely you will never need
to create on of these or handle one directly. It will be provided
for you by the Default
QueryRunner
instance.
Datatypes
data QueryRunnerColumn pgType haskellType Source #
A QueryRunnerColumn
pgType
haskellType
encodes how to turn
a value of Postgres type pgType
into a value of Haskell type
haskellType
. For example a value of type QueryRunnerColumn
PGText
String
encodes how to turn a PGText
result from the
database into a Haskell String
.
class QueryRunnerColumnDefault pgType haskellType where Source #
A QueryRunnerColumnDefault
pgType
haskellType
represents
the default way to turn a pgType
result from the database into a
Haskell value of type haskellType
.
Creating an instance of QueryRunnerColumnDefault
for your own types is
necessary for retrieving those types from the database.
You should use one of the three methods below for writing a
QueryRunnerColumnDefault
instance.
- If you already have a
FromField
instance for yourhaskellType
, usefieldQueryRunnerColumn
. (This is how most of the built-in instances are defined.) - If you don't have a
FromField
instance, usequeryRunnerColumn
if possible. See the documentation forqueryRunnerColumn
for an example. - If you have a more complicated case, but not a
FromField
instance, write aFieldParser
for your type and usefieldParserQueryRunnerColumn
. You can also add aFromField
instance using this.
queryRunnerColumnDefault :: QueryRunnerColumn pgType haskellType Source #
Creating now QueryRunnerColumn
s
fieldQueryRunnerColumn :: FromField haskell => QueryRunnerColumn pgType haskell Source #
fieldParserQueryRunnerColumn :: FieldParser haskell -> QueryRunnerColumn pgType haskell Source #