| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Opaleye.RunSelect
Synopsis
- runSelect :: Default FromFields fields haskells => Connection -> Select fields -> IO [haskells]
- runSelectI :: Default (Inferrable 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 Selects
runSelect :: Default FromFields fields haskells => Connection -> Select fields -> IO [haskells] Source #
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 FromFieldsrunSelect.
Example type specialization:
runSelect ::Select(FieldSqlInt4,FieldSqlText) -> IO [(Int, String)]
Assuming the makeAdaptorAndInstance splice has been run for the product type Foo:
runSelect ::Select(Foo (FieldSqlInt4) (FieldSqlText) (FieldSqlBool) -> IO [Foo Int String Bool]
runSelectI :: Default (Inferrable FromFields) fields haskells => Connection -> Select fields -> IO [haskells] Source #
Version of runSelect with better type inference
runSelectFold :: Default FromFields fields haskells => Connection -> Select fields -> b -> (b -> haskells -> IO b) -> IO b Source #
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
declareCursor :: Default FromFields fields haskells => Connection -> Select fields -> IO (Cursor haskells) Source #
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 FromFields
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 instanceDefaultFromFieldSqlFoo 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
FromFieldinstance for yourhaskellType, usefromPGSFromField. (This is how most of the built-in instances are defined.) - If you don't have a postgresql-simple
FromFieldinstance, but you do have an OpaleyeFromFieldvalue for the type it wraps useunsafeFromFieldif possible. See the documentation forunsafeFromFieldfor an example. - If you have a more complicated case, but not a
FromFieldinstance, write aFieldParserfor your type and usefromPGSFieldParser. You can also add aFromFieldinstance 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
runSelectTF :: Default FromFields (rec O) (rec H) => Connection -> Select (rec O) -> IO [rec H] Source #
Deprecated: Use runSelectI instead.