sqlite-simple-0.4.19.0: Mid-Level SQLite client library

Copyright | (c) 2011-2012 Leon P Smith (c) 2012-2013 Janne Hellsten
License | BSD3
Maintainer | Janne Hellsten <jjhellst@gmail.com>
Portability | portable
Safe Haskell | None
Language | Haskell2010

Database.SQLite.Simple.FromRow

Description

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.

Synopsis

- class GFromRow (f :: Type -> Type) where
  - gfromRow :: RowParser (f a)
- class FromRow a where
  - fromRow :: RowParser a
- data RowParser a
- field :: FromField a => RowParser a
- fieldWith :: FieldParser a -> RowParser a
- numFieldsRemaining :: RowParser Int

# Documentation

class 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`).

Since: 0.4.18.1

Methods

gfromRow :: RowParser (f a) #

#### Instances

Instances details

GFromRow (U1 :: Type -> Type) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods gfromRow :: RowParser (U1 a) #
(GFromRow a, GFromRow b) => GFromRow (a :*: b) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods gfromRow :: RowParser ((a :*: b) a0) #
FromField a => GFromRow (K1 i a :: Type -> Type) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods gfromRow :: RowParser (K1 i a a0) #
GFromRow a => GFromRow (M1 i c a) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods gfromRow :: RowParser (M1 i c a a0) #

class 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`.

Minimal complete definition

Nothing

Methods

fromRow :: RowParser a #

default fromRow :: (Generic a, GFromRow (Rep a)) => RowParser a #

#### Instances

Instances details

FromField a => FromRow (Only a) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (Only a) #
FromField a => FromRow [a] # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser [a] #
(FromRow a, FromRow b) => FromRow (a :. b) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a :. b) #
(FromField a, FromField b) => FromRow (a, b) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b) #
(FromField a, FromField b, FromField c) => FromRow (a, b, c) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c) #
(FromField a, FromField b, FromField c, FromField d) => FromRow (a, b, c, d) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d) #
(FromField a, FromField b, FromField c, FromField d, FromField e) => FromRow (a, b, c, d, e) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e) #
(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f) => FromRow (a, b, c, d, e, f) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e, f) #
(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g) => FromRow (a, b, c, d, e, f, g) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e, f, g) #
(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h) => FromRow (a, b, c, d, e, f, g, h) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e, f, g, h) #
(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i) => FromRow (a, b, c, d, e, f, g, h, i) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e, f, g, h, i) #
(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j) => FromRow (a, b, c, d, e, f, g, h, i, j) # |
Instance details Defined in Database.SQLite.Simple.FromRow Methods fromRow :: RowParser (a, b, c, d, e, f, g, h, i, j) #

data RowParser a #

#### Instances

Instances details

Alternative RowParser # |
Instance details Defined in Database.SQLite.Simple.Internal Methods empty :: RowParser a # (<|>) :: RowParser a -> RowParser a -> RowParser a # some :: RowParser a -> RowParser [a] # many :: RowParser a -> RowParser [a] #
Applicative RowParser # |
Instance details Defined in Database.SQLite.Simple.Internal Methods pure :: a -> RowParser a # (<*>) :: RowParser (a -> b) -> RowParser a -> RowParser b # liftA2 :: (a -> b -> c) -> RowParser a -> RowParser b -> RowParser c # (*>) :: RowParser a -> RowParser b -> RowParser b # (<*) :: RowParser a -> RowParser b -> RowParser a #
Functor RowParser # |
Instance details Defined in Database.SQLite.Simple.Internal Methods fmap :: (a -> b) -> RowParser a -> RowParser b # (<$) :: a -> RowParser b -> RowParser a #
Monad RowParser # |
Instance details Defined in Database.SQLite.Simple.Internal Methods (>>=) :: RowParser a -> (a -> RowParser b) -> RowParser b # (>>) :: RowParser a -> RowParser b -> RowParser b # return :: a -> RowParser a #
MonadPlus RowParser # |
Instance details Defined in Database.SQLite.Simple.Internal Methods mzero :: RowParser a # mplus :: RowParser a -> RowParser a -> RowParser a #

field :: FromField a => RowParser a #

fieldWith :: FieldParser a -> RowParser a #

numFieldsRemaining :: RowParser Int #