sql-fragment-0.0.1.0: SQL query combinator

Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.SQLFragment.TypeFamilies

Contents

Description

Defines common type families

Synopsis

Documentation

type family UnMaybe a

Remove the Maybe of a Type

Equations

UnMaybe (Maybe a) = a 
UnMaybe a = a 

type family NotNull as

Remove Maybe on all types of a list

Equations

NotNull [] = [] 
NotNull (a : as) = UnMaybe a : NotNull as 

type family Nullable as

Add Maybe on all types of a list if necessary

Equations

Nullable [] = [] 
Nullable (a : as) = Maybe (UnMaybe a) : Nullable as 

type family IfMaybe a b

Wrap a type in a Maybe if the source type is a Maybe Usefull to *convert* types whilst preserving the maybenes. Example, in SQL the type of "$1>0" !%! "hello" is '[Bool] or '[Maybe Bool] if the value is nullable.

Equations

IfMaybe (Maybe a) b = Maybe b 
IfMaybe a b = b 

type family IfMaybe2 a b c

Wrap a destination type in a `Maybe if one of the source types is also a Maybe.

Equations

IfMaybe2 (Maybe a) b c = Maybe c 
IfMaybe2 a (Maybe b) c = Maybe c 
IfMaybe2 a b c = c 

type family GetLabels as

Extract labels (proxy) of list of types

Equations

GetLabels [] = [] 
GetLabels (Tagged l a : as) = a : GetLabels as 
GetLabels (a : as) = GetLabels as 

type family GetLabel a :: k

Equations

GetLabel (Tagged (l :: k) a) = l 
GetLabel a = () 

type family GetValues as

Equations

GetValues [] = [] 
GetValues (a : as) = GetValue a : GetValues as 

type family GetValue a

Equations

GetValue (Tagged (l :: k) a) = a 
GetValue a = a 

class Boolable b

Instances

Boolable * Bool 
Boolable * (Maybe Bool) 
Boolable * b => Boolable * (Tagged k l b) 

class Boolables bs

Instances

Boolables ([] *) 
(Boolable * a, Boolables as) => Boolables ((:) * a as) 

List retypings

type family RelabelList ls ts

Equations

RelabelList [] t = RelabelList [] t 
RelabelList l [] = RelabelList l [] 
RelabelList (Tagged s b : ls) (t : ts) = Tagged s t : RelabelList ls ts