HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

  • Packageopaleye-0.10.8.0
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRunSelect.hs

Running Selects

3 declarations
valuerunSelect
  1. :: Default FromFields fields haskells
  2. => Connection
  3. -> Select fields

    ͘

  4. -> IO [haskells]
#

An alternative version of runSelectI that is more general but has worse type inference. runSelect's use of the Default FromFields typeclass means that the compiler will have trouble inferring types. It is strongly recommended that you provide full type signatures when using runSelect.

valuerunSelectFold
  1. :: Default FromFields fields haskells
  2. => Connection
  3. -> Select fields
  4. -> b
  5. -> (b -> haskells -> IO b)

    ͘

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

3 declarations
valuefoldForward
  1. :: Cursor haskells
  2. -> Int
  3. -> (a -> haskells -> IO a)
  4. -> a

    ͘

  5. -> IO (Either a a)
#

Fold over a chunk of rows, calling the supplied fold-like function on each row as it is received. In case the cursor is exhausted, a Left value is returned, otherwise a Right value is returned.

Creating new FromFields

1 declaration
valueunsafeFromField :: (b -> b') -> FromField sqlType b -> FromField sqlType' b'
#

Use unsafeFromField to make an instance to allow you to run queries on your own datatypes. For example:

newtype Foo = Foo Int
data SqlFoo

instance DefaultFromField SqlFoo Foo where
   defaultFromField = unsafeFromField Foo defaultFromField

It is "unsafe" because it does not check that the sqlType correctly corresponds to the Haskell type.

Explicit versions

3 declarations

Datatypes

4 declarations
datadata Cursor haskells
#

Cursor within a transaction.

datadata FromFields fields haskells
#

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

Instances11Profunctor, ProductProfunctor, SumProfunctor, Functor, Applicative, Default, …
newtypenewtype FromField sqlType haskellType
#

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

Instances19Functor, Default, …
classclass DefaultFromField sqlType haskellType where
#

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.

  1. If you already have a postgresql-simple FromField instance for your haskellType, use fromPGSFromField. (This is how most of the built-in instances are defined.)

  2. If you don't have a postgresql-simple FromField instance, but you do have an Opaleye FromField value for the type it wraps use unsafeFromField if possible. See the documentation for unsafeFromField for an example.

  3. If you have a more complicated case, but not a FromField instance, write a FieldParser for your type and use fromPGSFieldParser. You can also add a FromField instance using this.

Methods

Instances41DefaultFromField, …

Helper functions

2 declarations

Deprecated

1 declaration