HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulesqlite-simple-0.4.19.0Haskell2010

Database.SQLite.Simple.FromRow

The FromRow typeclass, for converting a row of results returned by a SQL query into a more useful Haskell representation.

Predefined instances are provided for tuples containing up to ten elements.

  • 1 type
  • 2 classes
  • 3 values
classclass GFromRow (f :: Type -> Type) where
#

Generic derivation of FromRow.

Instantiating FromRow can in some cases be quite tedious. Luckily we can derive it generically in some cases where the type at hand has a Generic instance. The current implementation only works for a (n-ary) product types. So we would not be able to e.g. derive a FromRow instance for

data Bool = True | False

We can, however, derive a generic instance for the User type (see the example in FromRow).

Methods

Instances4GFromRow
  • GFromRow U1Defined in sqlite-simple-0.4.19.0 · Database.SQLite.Simple.FromRow
  • FromField a => GFromRow (K1 i a)Defined in sqlite-simple-0.4.19.0 · Database.SQLite.Simple.FromRow
  • (GFromRow a, GFromRow b) => GFromRow (a :*: b)Defined in sqlite-simple-0.4.19.0 · Database.SQLite.Simple.FromRow
  • GFromRow a => GFromRow (M1 i c a)Defined in sqlite-simple-0.4.19.0 · Database.SQLite.Simple.FromRow
classclass FromRow a where
#

A collection type that can be converted from a sequence of fields. Instances are provided for tuples up to 10 elements and lists of any length.

Note that instances can defined outside of sqlite-simple, which is often useful. For example, here's an instance for a user-defined pair:

data User = User { name :: String, fileQuota :: Int }

instance FromRow User where
    fromRow = User <$> field <*> field

The number of calls to field must match the number of fields returned in a single row of the query result. Otherwise, a ConversionFailed exception will be thrown.

Note the caveats associated with user-defined implementations of fromRow.

Generic implementation

Since version 0.4.18.1 it is possible in some cases to derive a generic implementation for FromRow. With a Generic instance for User, the example above could be written:

instance FromRow User where

With -XDeriveAnyClass -XDerivingStrategies the same can be written:

deriving anyclass instance FromRow User

For more details refer to GFromRow.

Methods

Instances12FromRow, …
newtypenewtype RowParser a
#
Instances5Monad, Functor, Applicative, Alternative, MonadPlus