Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for creating selectors for non-record types.
In general, you should really use record types for your tables and
their record labels (i.e. #label) as selectors using
the OverloadedLabels
extension instead.
Synopsis
- type Selectors r = Sels r (Rep r)
- class GSelectors t (f :: * -> *)
- selectors :: forall a. (Relational a, GSelectors a (Rep a)) => Table a -> Selectors a
- tableWithSelectors :: forall a. (Relational a, GSelectors a (Rep a)) => TableName -> [Attr a] -> (Table a, Selectors a)
Documentation
class GSelectors t (f :: * -> *) Source #
Any table type that can have selectors generated.
mkSel
Instances
(GSelectors t a, GSelectors t b, Sels t (a :*: b) ~ (Sels t a :*: Sels t b)) => GSelectors t (a :*: b) Source # | |
GSelectors t (a :*: (b :*: c)) => GSelectors t ((a :*: b) :*: c) Source # | |
(SqlRow t, SqlType a) => GSelectors t (K1 i a :: Type -> Type) Source # | |
(GSelectors t f, Sels t f ~ Sels t (M1 x y f)) => GSelectors t (M1 x y f) Source # | |
selectors :: forall a. (Relational a, GSelectors a (Rep a)) => Table a -> Selectors a Source #
Generate selector functions for the given table. Selectors can be used to access the fields of a query result tuple, avoiding the need to pattern match on the entire tuple.
tbl :: Table (Int, Text) tbl = table "foo" [] (tblBar :*: tblBaz) = selectors tbl q :: Query s Text q = do row <- select tbl return (row ! tblBaz)
tableWithSelectors :: forall a. (Relational a, GSelectors a (Rep a)) => TableName -> [Attr a] -> (Table a, Selectors a) Source #
A pair of the table with the given name and columns, and all its selectors. For example:
tbl :: Table (Int, Text) (tbl, tblBar :*: tblBaz) = tableWithSelectors "foo" [] q :: Query s Text q = tblBaz `from` select tbl