Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Opaleye.RunSelect
Synopsis
- runSelectI :: Default (Inferrable FromFields) fields haskells => Connection -> Select fields -> IO [haskells]
- runSelect :: Default FromFields fields haskells => Connection -> Select fields -> IO [haskells]
- runSelectFold :: Default FromFields fields haskells => Connection -> Select fields -> b -> (b -> haskells -> IO b) -> IO b
- declareCursor :: Default FromFields fields haskells => Connection -> Select fields -> IO (Cursor haskells)
- closeCursor :: Cursor fields -> IO ()
- foldForward :: Cursor haskells -> Int -> (a -> haskells -> IO a) -> a -> IO (Either a a)
- unsafeFromField :: (b -> b') -> FromField sqlType b -> FromField sqlType' b'
- runSelectExplicit :: FromFields fields haskells -> Connection -> Select fields -> IO [haskells]
- runSelectFoldExplicit :: FromFields fields haskells -> Connection -> Select fields -> b -> (b -> haskells -> IO b) -> IO b
- declareCursorExplicit :: FromFields fields haskells -> Connection -> Select fields -> IO (Cursor haskells)
- data Cursor haskells
- data FromFields fields haskells
- data FromField sqlType haskellType
- class DefaultFromField sqlType haskellType where
- defaultFromField :: FromField sqlType haskellType
- fromPGSFromField :: FromField haskell => FromField pgType haskell
- fromPGSFieldParser :: FieldParser haskell -> FromField pgType haskell
- runSelectTF :: Default FromFields (rec O) (rec H) => Connection -> Select (rec O) -> IO [rec H]
Running Select
s
Arguments
:: Default (Inferrable FromFields) fields haskells | |
=> Connection | |
-> Select fields | ͘ |
-> IO [haskells] |
Arguments
:: Default FromFields fields haskells | |
=> Connection | |
-> Select fields | ͘ |
-> IO [haskells] |
An alternative version of runSelectI
that is more general but
has worse type inference. runSelect
's use of the
typeclass means that the
compiler will have trouble inferring types. It is strongly
recommended that you provide full type signatures when using
Default
FromFields
runSelect
.
@
Arguments
:: Default FromFields fields haskells | |
=> Connection | |
-> Select fields | |
-> b | |
-> (b -> haskells -> IO b) | ͘ |
-> IO b |
runSelectFold
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.
Cursor interface
Arguments
:: Default FromFields fields haskells | |
=> Connection | |
-> Select fields | ͘ |
-> IO (Cursor haskells) |
Declare a temporary cursor. The cursor is given a unique name for the given connection.
closeCursor :: Cursor fields -> IO () Source #
Close the given cursor.
Creating new FromField
s
unsafeFromField :: (b -> b') -> FromField sqlType b -> FromField sqlType' b' Source #
Use unsafeFromField
to make an instance to allow you to run
queries on your own datatypes. For example:
newtype Foo = Foo Int data SqlFoo instanceDefaultFromField
SqlFoo Foo wheredefaultFromField
= unsafeFromField Foo defaultFromField
It is "unsafe" because it does not check that the sqlType
correctly corresponds to the Haskell type.
Explicit versions
runSelectExplicit :: FromFields fields haskells -> Connection -> Select fields -> IO [haskells] Source #
runSelectFoldExplicit :: FromFields fields haskells -> Connection -> Select fields -> b -> (b -> haskells -> IO b) -> IO b Source #
declareCursorExplicit :: FromFields fields haskells -> Connection -> Select fields -> IO (Cursor haskells) Source #
Datatypes
data FromFields fields haskells Source #
A FromFields
specifies how to convert Postgres values (fields
)
into Haskell values (haskells
). Most likely you will never need
to create one of these or handle one directly. It will be provided
for you by the Default
FromFields
instance.
"FromFields
fields
haskells
" corresponds to
postgresql-simple's "RowParser
haskells
". "Default
FromFields
fields
haskells
" corresponds to
postgresql-simple's "FromRow
haskells
".
Instances
data FromField sqlType haskellType Source #
A FromField
sqlType
haskellType
encodes how to turn
a value of Postgres type sqlType
into a value of Haskell type
haskellType
. For example a value of type FromField
SqlText
String
encodes how to turn a SqlText
result from the
database into a Haskell String
.
"FromField
sqlType
haskellType
" corresponds to
postgresql-simple's "FieldParser
haskellType
".
Instances
class DefaultFromField sqlType haskellType where Source #
A DefaultFromField
sqlType
haskellType
represents
the default way to turn a sqlType
result from the database into a
Haskell value of type haskellType
.
"DefaultFromField
sqlType
haskellType
" corresponds
to postgresql-simple's "FromField
haskellType
".
Creating an instance of DefaultFromField
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
DefaultFromField
instance.
- If you already have a postgresql-simple
FromField
instance for yourhaskellType
, usefromPGSFromField
. (This is how most of the built-in instances are defined.) - If you don't have a postgresql-simple
FromField
instance, but you do have an OpaleyeFromField
value for the type it wraps useunsafeFromField
if possible. See the documentation forunsafeFromField
for an example. - If you have a more complicated case, but not a
FromField
instance, write aFieldParser
for your type and usefromPGSFieldParser
. You can also add aFromField
instance using this.
Methods
defaultFromField :: FromField sqlType haskellType Source #
Instances
Helper functions
fromPGSFromField :: FromField haskell => FromField pgType haskell Source #
fromPGSFieldParser :: FieldParser haskell -> FromField pgType haskell Source #
Deprecated
Arguments
:: Default FromFields (rec O) (rec H) | |
=> Connection | |
-> Select (rec O) | ͘ |
-> IO [rec H] |
Deprecated: Use runSelectI
instead.