sqlite-simple-0.4.19.0: Mid-Level SQLite client library
Copyright(c) 2011-2012 Leon P Smith
(c) 2012-2013 Janne Hellsten
LicenseBSD3
MaintainerJanne Hellsten <jjhellst@gmail.com>
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Documentation

class GFromRow f where Source #

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) Source #

Instances

Instances details
GFromRow (U1 :: Type -> Type) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

gfromRow :: RowParser (U1 a) Source #

(GFromRow a, GFromRow b) => GFromRow (a :*: b) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

gfromRow :: RowParser ((a :*: b) a0) Source #

FromField a => GFromRow (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

gfromRow :: RowParser (K1 i a a0) Source #

GFromRow a => GFromRow (M1 i c a) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

gfromRow :: RowParser (M1 i c a a0) Source #

class FromRow a where Source #

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 Source #

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

Instances

Instances details
FromField a => FromRow (Only a) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (Only a) Source #

FromField a => FromRow [a] Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser [a] Source #

(FromRow a, FromRow b) => FromRow (a :. b) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a :. b) Source #

(FromField a, FromField b) => FromRow (a, b) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b) Source #

(FromField a, FromField b, FromField c) => FromRow (a, b, c) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c) Source #

(FromField a, FromField b, FromField c, FromField d) => FromRow (a, b, c, d) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e) => FromRow (a, b, c, d, e) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f) => FromRow (a, b, c, d, e, f) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e, f) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g) => FromRow (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e, f, g) Source #

(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) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e, f, g, h) Source #

(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) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e, f, g, h, i) Source #

(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) Source # 
Instance details

Defined in Database.SQLite.Simple.FromRow

Methods

fromRow :: RowParser (a, b, c, d, e, f, g, h, i, j) Source #

data RowParser a Source #

Instances

Instances details
Alternative RowParser Source # 
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 Source # 
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 Source # 
Instance details

Defined in Database.SQLite.Simple.Internal

Methods

fmap :: (a -> b) -> RowParser a -> RowParser b #

(<$) :: a -> RowParser b -> RowParser a #

Monad RowParser Source # 
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 Source # 
Instance details

Defined in Database.SQLite.Simple.Internal

Methods

mzero :: RowParser a #

mplus :: RowParser a -> RowParser a -> RowParser a #