squeal-postgresql-0.3.0.0: Squeal PostgreSQL Library

Copyright(c) Eitan Chatav 2017
Maintainereitan@morphism.tech
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Squeal.PostgreSQL.Schema

Contents

Description

This module provides a type-level DSL for kinds of Postgres types, tables, schema, constraints, aliases, enumerated labels, and groupings. It also defines useful type families to operate on these. Finally, it defines an embedding of Haskell types into Postgres types.

Synopsis

Types

data PGType Source #

PGType is the promoted datakind of PostgreSQL types.

>>> import Squeal.PostgreSQL.Schema
>>> :kind 'PGbool
'PGbool :: PGType

Constructors

PGbool

logical Boolean (true/false)

PGint2

signed two-byte integer

PGint4

signed four-byte integer

PGint8

signed eight-byte integer

PGnumeric

arbitrary precision numeric type

PGfloat4

single precision floating-point number (4 bytes)

PGfloat8

double precision floating-point number (8 bytes)

PGchar Nat

fixed-length character string

PGvarchar Nat

variable-length character string

PGtext

variable-length character string

PGbytea

binary data ("byte array")

PGtimestamp

date and time (no time zone)

PGtimestamptz

date and time, including time zone

PGdate

calendar date (year, month, day)

PGtime

time of day (no time zone)

PGtimetz

time of day, including time zone

PGinterval

time span

PGuuid

universally unique identifier

PGinet

IPv4 or IPv6 host address

PGjson

textual JSON data

PGjsonb

binary JSON data, decomposed

PGvararray PGType

variable length array

PGfixarray Nat PGType

fixed length array

PGenum [Symbol] 
PGcomposite [(Symbol, PGType)] 
UnsafePGType Symbol

an escape hatch for unsupported PostgreSQL types

Instances

PGAvg PGType PGint2 PGnumeric Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGint4 PGnumeric Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGint8 PGnumeric Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGnumeric PGnumeric Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGnumeric) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGfloat4 PGfloat8 Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGfloat8) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGfloat8) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGfloat8 PGfloat8 Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGfloat8) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGfloat8) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

PGAvg PGType PGinterval PGinterval Source # 

Methods

avg :: Expression schema relations Ungrouped params (nullity PGinterval) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

avgDistinct :: Expression schema relations Ungrouped params (nullity PGinterval) -> Expression schema relations (Grouped bys) params (nullity avg) Source #

class HasOid (ty :: PGType) where Source #

The object identifier of a PGType.

>>> :set -XTypeApplications
>>> oid @'PGbool
16

Minimal complete definition

oid

Methods

oid :: Word32 Source #

data NullityType Source #

NullityType encodes the potential presence or definite absence of a NULL allowing operations which are sensitive to such to be well typed.

>>> :kind 'Null 'PGint4
'Null 'PGint4 :: NullityType
>>> :kind 'NotNull ('PGvarchar 50)
'NotNull ('PGvarchar 50) :: NullityType

Constructors

Null PGType

NULL may be present

NotNull PGType

NULL is absent

Instances

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) Source #

(KnownNat n, HasParameter ((-) n 1) schema params ty) => HasParameter n schema ((:) NullityType ty' params) ty Source # 

Methods

parameter :: TypeExpression schema (PGTypeOf ty) -> Expression schema relations grouping ((NullityType ': ty') params) ty Source #

HasParameter 1 schema ((:) NullityType ty1 tys) ty1 Source # 

Methods

parameter :: TypeExpression schema (PGTypeOf ty1) -> Expression schema relations grouping ((NullityType ': ty1) tys) ty1 Source #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) #

FromValue pg y => FromColumnValue ((:::) NullityType column (NotNull pg)) y Source # 
FromValue pg y => FromColumnValue ((:::) NullityType column (Null pg)) (Maybe y) Source # 
(~) k ty0 ty1 => SamePGType ((:::) (ColumnConstraint, NullityType) alias0 ((:=>) ColumnConstraint NullityType def0 (nullity0 ty0))) ((:::) (ColumnConstraint, NullityType) alias1 ((:=>) ColumnConstraint NullityType def1 (nullity1 ty1))) Source # 
AddColumn ((:=>) ColumnConstraint NullityType Def ty) Source # 

Methods

addColumn :: (KnownSymbol column, Has SchemumType tab schema (Table table0), (TableType ~ table0) ((TableConstraints :=> ColumnsType) constraints columns), ((TableConstraints, [(Symbol, ColumnType)]) ~ table1) ((TableConstraints :=> [(Symbol, ColumnType)]) constraints (Create ColumnType column ((ColumnConstraint :=> NullityType) Def ty) columns))) => Alias column -> ColumnTypeExpression schema ((ColumnConstraint :=> NullityType) Def ty) -> AlterTable tab table1 schema Source #

AddColumn ((:=>) ColumnConstraint NullityType NoDef (Null ty)) Source # 

Methods

addColumn :: (KnownSymbol column, Has SchemumType tab schema (Table table0), (TableType ~ table0) ((TableConstraints :=> ColumnsType) constraints columns), ((TableConstraints, [(Symbol, ColumnType)]) ~ table1) ((TableConstraints :=> [(Symbol, ColumnType)]) constraints (Create ColumnType column ((ColumnConstraint :=> NullityType) NoDef (Null ty)) columns))) => Alias column -> ColumnTypeExpression schema ((ColumnConstraint :=> NullityType) NoDef (Null ty)) -> AlterTable tab table1 schema Source #

type ColumnType = (ColumnConstraint, NullityType) Source #

ColumnType encodes the allowance of DEFAULT and NULL and the base PGType for a column.

>>> :set -XTypeFamilies -XTypeInType
>>> import GHC.TypeLits
>>> type family IdColumn :: ColumnType where IdColumn = 'Def :=> 'NotNull 'PGint4
>>> type family EmailColumn :: ColumnType where EmailColumn = 'NoDef :=> 'Null 'PGtext

Tables

type ColumnsType = [(Symbol, ColumnType)] Source #

ColumnsType is a row of ColumnTypes.

>>> :{
type family UsersColumns :: ColumnsType where
  UsersColumns =
    '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
     , "id"   :::   'Def :=> 'NotNull 'PGint4
     ]
:}

type RelationType = [(Symbol, NullityType)] Source #

RelationType is a row of NullityType

>>> :{
type family PersonRelation :: RelationType where
  PersonRelation =
    '[ "name"        ::: 'NotNull 'PGtext
     , "age"         ::: 'NotNull 'PGint4
     , "dateOfBirth" :::    'Null 'PGdate
     ]
:}

type family NilRelation :: RelationType where ... Source #

A monokinded empty RelationType.

Equations

NilRelation = '[] 

type RelationsType = [(Symbol, RelationType)] Source #

RelationsType is a row of RelationTypes, thought of as a product.

type TableType = (TableConstraints, ColumnsType) Source #

TableType encodes a row of constraints on a table as well as the types of its columns.

>>> :{
type family UsersTable :: TableType where
  UsersTable =
    '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
    '[ "id"       :::   'Def :=> 'NotNull 'PGint4
     , "name"     ::: 'NoDef :=> 'NotNull 'PGtext
     ]
:}

Schema

data SchemumType Source #

A SchemumType is a user-defined type, either a Table, View or Typedef.

Instances

Category SchemaType Definition # 

Methods

id :: cat a a #

(.) :: cat b c -> cat a b -> cat a c #

type SchemaType = [(Symbol, SchemumType)] Source #

The schema of a database consists of a list of aliased, user-defined SchemumTypes.

Constraints

type (:=>) constraint ty = '(constraint, ty) infixr 7 Source #

The constraint operator, :=> is a type level pair between a "constraint" and some type, for use in pairing a ColumnConstraint with a NullityType to produce a ColumnType or a TableConstraints and a ColumnsType to produce a TableType.

data ColumnConstraint Source #

ColumnConstraint encodes the availability of DEFAULT for inserts and updates. A column can be assigned a default value. A data Manipulation command can also request explicitly that a column be set to its default value, without having to know what that value is.

Constructors

Def

DEFAULT is available for inserts and updates

NoDef

DEFAULT is unavailable for inserts and updates

Instances

(~) k ty0 ty1 => SamePGType ((:::) (ColumnConstraint, NullityType) alias0 ((:=>) ColumnConstraint NullityType def0 (nullity0 ty0))) ((:::) (ColumnConstraint, NullityType) alias1 ((:=>) ColumnConstraint NullityType def1 (nullity1 ty1))) Source # 
AddColumn ((:=>) ColumnConstraint NullityType Def ty) Source # 

Methods

addColumn :: (KnownSymbol column, Has SchemumType tab schema (Table table0), (TableType ~ table0) ((TableConstraints :=> ColumnsType) constraints columns), ((TableConstraints, [(Symbol, ColumnType)]) ~ table1) ((TableConstraints :=> [(Symbol, ColumnType)]) constraints (Create ColumnType column ((ColumnConstraint :=> NullityType) Def ty) columns))) => Alias column -> ColumnTypeExpression schema ((ColumnConstraint :=> NullityType) Def ty) -> AlterTable tab table1 schema Source #

AddColumn ((:=>) ColumnConstraint NullityType NoDef (Null ty)) Source # 

Methods

addColumn :: (KnownSymbol column, Has SchemumType tab schema (Table table0), (TableType ~ table0) ((TableConstraints :=> ColumnsType) constraints columns), ((TableConstraints, [(Symbol, ColumnType)]) ~ table1) ((TableConstraints :=> [(Symbol, ColumnType)]) constraints (Create ColumnType column ((ColumnConstraint :=> NullityType) NoDef (Null ty)) columns))) => Alias column -> ColumnTypeExpression schema ((ColumnConstraint :=> NullityType) NoDef (Null ty)) -> AlterTable tab table1 schema Source #

data TableConstraint Source #

TableConstraint encodes various forms of data constraints of columns in a table. TableConstraints give you as much control over the data in your tables as you wish. If a user attempts to store data in a column that would violate a constraint, an error is raised. This applies even if the value came from the default value definition.

type family NilTableConstraints :: TableConstraints where ... Source #

A monokinded empty TableConstraints.

Equations

NilTableConstraints = '[] 

type family Uniquely (key :: [Symbol]) (constraints :: TableConstraints) :: Constraint where ... Source #

A ForeignKey must reference columns that either are a PrimaryKey or form a Unique constraint.

Equations

Uniquely key ((uq ::: Unique key) ': constraints) = () 
Uniquely key ((pk ::: PrimaryKey key) ': constraints) = () 
Uniquely key (_ ': constraints) = Uniquely key constraints 

Aliases

type (:::) (alias :: Symbol) ty = '(alias, ty) infixr 6 Source #

The alias operator ::: is like a promoted version of As, a type level pair between an alias and some type.

data Alias (alias :: Symbol) Source #

Aliases are proxies for a type level string or Symbol and have an IsLabel instance so that with -XOverloadedLabels

>>> :set -XOverloadedLabels
>>> #foobar :: Alias "foobar"
Alias

Constructors

Alias 

Instances

IsQualified table column (Alias table, Alias column) Source # 

Methods

(!) :: Alias table -> Alias column -> (Alias table, Alias column) Source #

(~) Symbol alias1 alias2 => IsLabel alias1 (Alias alias2) Source # 

Methods

fromLabel :: Alias alias2 #

((~) Symbol alias0 alias1, (~) Symbol alias0 alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Symbol Alias ((:::) Symbol alias1 alias2)) Source # 

Methods

fromLabel :: Aliased Symbol Alias ((Symbol ::: alias1) alias2) #

(~) [Symbol] aliases ((:) Symbol alias ([] Symbol)) => IsLabel alias (NP Symbol Alias aliases) Source # 

Methods

fromLabel :: NP Symbol Alias aliases #

Eq (Alias alias) Source # 

Methods

(==) :: Alias alias -> Alias alias -> Bool #

(/=) :: Alias alias -> Alias alias -> Bool #

Ord (Alias alias) Source # 

Methods

compare :: Alias alias -> Alias alias -> Ordering #

(<) :: Alias alias -> Alias alias -> Bool #

(<=) :: Alias alias -> Alias alias -> Bool #

(>) :: Alias alias -> Alias alias -> Bool #

(>=) :: Alias alias -> Alias alias -> Bool #

max :: Alias alias -> Alias alias -> Alias alias #

min :: Alias alias -> Alias alias -> Alias alias #

Show (Alias alias) Source # 

Methods

showsPrec :: Int -> Alias alias -> ShowS #

show :: Alias alias -> String #

showList :: [Alias alias] -> ShowS #

Generic (Alias alias) Source # 

Associated Types

type Rep (Alias alias) :: * -> * #

Methods

from :: Alias alias -> Rep (Alias alias) x #

to :: Rep (Alias alias) x -> Alias alias #

NFData (Alias alias) Source # 

Methods

rnf :: Alias alias -> () #

KnownSymbol alias => RenderSQL (Alias alias) Source # 

Methods

renderSQL :: Alias alias -> ByteString Source #

type Rep (Alias alias) Source # 
type Rep (Alias alias) = D1 * (MetaData "Alias" "Squeal.PostgreSQL.Schema" "squeal-postgresql-0.3.0.0-E9Ax8VffdgQ3ZC5pqeEIaA" False) (C1 * (MetaCons "Alias" PrefixI False) (U1 *))

renderAlias :: KnownSymbol alias => Alias alias -> ByteString Source #

>>> renderAlias #jimbob
"\"jimbob\""

renderAliases :: All KnownSymbol aliases => NP Alias aliases -> [ByteString] Source #

>>> import Generics.SOP (NP(..))
>>> renderAliases (#jimbob :* #kandi :* Nil)
["\"jimbob\"","\"kandi\""]

data Aliased expression aliased where Source #

The As operator is used to name an expression. As is like a demoted version of :::.

>>> Just "hello" `As` #hi :: Aliased Maybe ("hi" ::: String)
As (Just "hello") Alias

Constructors

As :: KnownSymbol alias => expression ty -> Alias alias -> Aliased expression (alias ::: ty) 

Instances

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) Source #

((~) Symbol alias0 alias1, (~) Symbol alias0 alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Symbol Alias ((:::) Symbol alias1 alias2)) Source # 

Methods

fromLabel :: Aliased Symbol Alias ((Symbol ::: alias1) alias2) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) #

Eq (expression ty) => Eq (Aliased k expression ((:::) k alias ty)) Source # 

Methods

(==) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

(/=) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

Ord (expression ty) => Ord (Aliased k expression ((:::) k alias ty)) Source # 

Methods

compare :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Ordering #

(<) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

(<=) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

(>) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

(>=) :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Bool #

max :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) #

min :: Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) -> Aliased k expression ((k ::: alias) ty) #

Show (expression ty) => Show (Aliased k expression ((:::) k alias ty)) Source # 

Methods

showsPrec :: Int -> Aliased k expression ((k ::: alias) ty) -> ShowS #

show :: Aliased k expression ((k ::: alias) ty) -> String #

showList :: [Aliased k expression ((k ::: alias) ty)] -> ShowS #

renderAliasedAs :: (forall ty. expression ty -> ByteString) -> Aliased expression aliased -> ByteString Source #

>>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
>>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
"Just AS \"an_int\""

type family AliasesOf aliaseds where ... Source #

AliasesOf retains the AliasesOf in a row.

Equations

AliasesOf '[] = '[] 
AliasesOf ((alias ::: ty) ': tys) = alias ': AliasesOf tys 

class (SListI (ZipAs ns xs), All KnownSymbol ns) => ZipAliased ns xs where Source #

The ZipAliased class provides a type family for zipping Symbol lists together with arbitrary lists of the same size, with an associated type family ZipAs, together with a method zipAs for zipping heterogeneous lists of Aliases together with a heterogeneous list of expressions into a heterogeneous list of Aliased expressions.

Minimal complete definition

zipAs

Associated Types

type ZipAs (ns :: [Symbol]) (xs :: [k]) = (zs :: [(Symbol, k)]) | zs -> ns xs Source #

Methods

zipAs :: NP Alias ns -> NP expr xs -> NP (Aliased expr) (ZipAs ns xs) Source #

Instances

ZipAliased k ([] Symbol) ([] k) Source # 

Associated Types

type ZipAs [Symbol] ([k] :: [Symbol]) (xs :: [[Symbol]]) = (zs :: [(Symbol, k)]) Source #

Methods

zipAs :: NP Symbol Alias [k] -> NP [Symbol] expr xs -> NP (Symbol, [Symbol]) (Aliased [Symbol] expr) (ZipAs [Symbol] [k] xs) Source #

(KnownSymbol n, ZipAliased k ns xs) => ZipAliased k ((:) Symbol n ns) ((:) k x xs) Source # 

Associated Types

type ZipAs ((Symbol ': n) ns) ((k ': x) xs :: [Symbol]) (xs :: [(Symbol ': n) ns]) = (zs :: [(Symbol, k)]) Source #

Methods

zipAs :: NP Symbol Alias ((k ': x) xs) -> NP ((Symbol ': n) ns) expr xs -> NP (Symbol, (Symbol ': n) ns) (Aliased ((Symbol ': n) ns) expr) (ZipAs ((Symbol ': n) ns) ((k ': x) xs) xs) Source #

class KnownSymbol alias => Has (alias :: Symbol) (fields :: [(Symbol, kind)]) (field :: kind) | alias fields -> field Source #

Has alias fields field is a constraint that proves that fields has a field of alias ::: field, inferring field from alias and fields.

Instances

(KnownSymbol alias, Has kind alias fields field) => Has kind alias ((:) (Symbol, kind) field' fields) field Source # 
KnownSymbol alias => Has kind alias ((:) (Symbol, kind) ((:::) kind alias field) fields) field Source # 

type HasUnique alias fields field = fields ~ '[alias ::: field] Source #

HasUnique alias fields field is a constraint that proves that fields is a singleton of alias ::: field.

class All KnownSymbol aliases => HasAll (aliases :: [Symbol]) (fields :: [(Symbol, kind)]) (subfields :: [(Symbol, kind)]) | aliases fields -> subfields Source #

HasAll extends Has to take lists of aliases and fields and infer a list of subfields.

Instances

HasAll kind ([] Symbol) fields ([] (Symbol, kind)) Source # 
(Has k alias fields field, HasAll k aliases fields subfields) => HasAll k ((:) Symbol alias aliases) fields ((:) (Symbol, k) ((:::) k alias field) subfields) Source # 

class IsLabel (x :: Symbol) a where #

Minimal complete definition

fromLabel

Methods

fromLabel :: a #

Instances

(~) Symbol alias1 alias2 => IsLabel alias1 (Alias alias2) # 

Methods

fromLabel :: Alias alias2 #

Has SchemumType alias schema (Typedef ty) => IsLabel alias (TypeExpression schema ty) # 

Methods

fromLabel :: TypeExpression schema ty #

Has PGType field fields ty => IsLabel field (Expression schema relation grouping params (nullity (PGcomposite fields)) -> Expression schema relation grouping params (Null ty)) # 

Methods

fromLabel :: Expression schema relation grouping params (nullity (PGcomposite fields)) -> Expression schema relation grouping params (Null ty) #

((~) Symbol alias0 alias1, (~) Symbol alias0 alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Symbol Alias ((:::) Symbol alias1 alias2)) # 

Methods

fromLabel :: Aliased Symbol Alias ((Symbol ::: alias1) alias2) #

(~) [Symbol] aliases ((:) Symbol alias ([] Symbol)) => IsLabel alias (NP Symbol Alias aliases) # 

Methods

fromLabel :: NP Symbol Alias aliases #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) # 

Methods

fromLabel :: NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) # 

Methods

fromLabel :: Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsLabel column (Expression schema relations (Grouped bys) params ty) # 

Methods

fromLabel :: Expression schema relations (Grouped bys) params ty #

(HasUnique [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsLabel column (Expression schema relations Ungrouped params ty) # 

Methods

fromLabel :: Expression schema relations Ungrouped params ty #

class IsQualified table column expression where Source #

Analagous to IsLabel, the constraint IsQualified defines ! for a column alias qualified by a table alias.

Minimal complete definition

(!)

Methods

(!) :: Alias table -> Alias column -> expression infixl 9 Source #

Instances

IsQualified table column (Alias table, Alias column) Source # 

Methods

(!) :: Alias table -> Alias column -> (Alias table, Alias column) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations (Grouped bys) params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (Aliased NullityType (Expression schema relations (Grouped bys) params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations (Grouped bys) params) ((NullityType ::: column) ty) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) ((:) (Symbol, NullityType) ((:::) NullityType column ty) ([] (Symbol, NullityType)))) Source # 

Methods

(!) :: Alias relation -> Alias column -> NP (Symbol, NullityType) (Aliased NullityType (Expression schema relations Ungrouped params)) (((Symbol, NullityType) ': (NullityType ::: column) ty) [(Symbol, NullityType)]) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (Aliased NullityType (Expression schema relations Ungrouped params) ((:::) NullityType column ty)) Source # 

Methods

(!) :: Alias relation -> Alias column -> Aliased NullityType (Expression schema relations Ungrouped params) ((NullityType ::: column) ty) Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty, GroupedBy [(Symbol, Symbol)] relation column bys) => IsQualified relation column (Expression schema relations (Grouped bys) params ty) Source # 

Methods

(!) :: Alias relation -> Alias column -> Expression schema relations (Grouped bys) params ty Source #

(Has [(Symbol, NullityType)] relation relations columns, Has NullityType column columns ty) => IsQualified relation column (Expression schema relations Ungrouped params ty) Source # 

Methods

(!) :: Alias relation -> Alias column -> Expression schema relations Ungrouped params ty Source #

Enumerated Labels

class IsPGlabel (label :: Symbol) expr where Source #

IsPGlabel looks very much like the IsLabel class. Whereas the overloaded label, fromLabel is used for column references, labels are used for enum terms. A label is called with type application like `label @"beef"`.

Minimal complete definition

label

Methods

label :: expr Source #

Instances

(~) Symbol label label' => IsPGlabel label (PGlabel label') Source # 

Methods

label :: PGlabel label' Source #

(KnownSymbol label, In Symbol label labels) => IsPGlabel label (Expression schema relations grouping params (nullity (PGenum labels))) Source # 

Methods

label :: Expression schema relations grouping params (nullity (PGenum labels)) Source #

data PGlabel (label :: Symbol) Source #

A PGlabel unit type with an IsPGlabel instance

Constructors

PGlabel 

Instances

(~) Symbol label label' => IsPGlabel label (PGlabel label') Source # 

Methods

label :: PGlabel label' Source #

renderLabel :: KnownSymbol label => proxy label -> ByteString Source #

Renders a label

renderLabels :: All KnownSymbol labels => NP PGlabel labels -> [ByteString] Source #

Renders a list of labels

Grouping

data Grouping Source #

Grouping is an auxiliary namespace, created by GROUP BY clauses (group), and used for typesafe aggregation

Constructors

Ungrouped

no aggregation permitted

Grouped [(Symbol, Symbol)]

aggregation required for any column which is not grouped

class (KnownSymbol relation, KnownSymbol column) => GroupedBy relation column bys Source #

A GroupedBy constraint indicates that a table qualified column is a member of the auxiliary namespace created by GROUP BY clauses and thus, may be called in an output Expression without aggregating.

Instances

(KnownSymbol relation, KnownSymbol column) => GroupedBy [(k, Symbol)] relation column ((:) (k, Symbol) ((,) k Symbol table column) bys) Source # 
(KnownSymbol relation, KnownSymbol column, GroupedBy [a] relation column bys) => GroupedBy [a] relation column ((:) a tabcol bys) Source # 

Type Families

type family Join xs ys where ... Source #

Join is simply promoted ++ and is used in JOINs in FromClauses.

Equations

Join '[] ys = ys 
Join (x ': xs) ys = x ': Join xs ys 

type family With (relations :: RelationsType) (schema :: SchemaType) :: SchemaType where ... Source #

Used in with.

Equations

With '[] schema = schema 
With ((alias ::: rel) ': rels) schema = (alias ::: View rel) ': With rels schema 

type family Create alias x xs where ... Source #

Create alias x xs adds alias ::: x to the end of xs and is used in createTable statements and in ALTER TABLE addColumn.

Equations

Create alias x '[] = '[alias ::: x] 
Create alias x ((alias ::: y) ': xs) = TypeError ((Text "Create: alias " :<>: ShowType alias) :<>: Text "already in use") 
Create alias y (x ': xs) = x ': Create alias y xs 

type family Drop alias xs where ... Source #

Drop alias xs removes the type associated with alias in xs and is used in dropTable statements and in ALTER TABLE dropColumn statements.

Equations

Drop alias ((alias ::: x) ': xs) = xs 
Drop alias (x ': xs) = x ': Drop alias xs 

type family Alter alias x xs where ... Source #

Alter alias x xs replaces the type associated with an alias in xs with the type x and is used in alterTable and alterColumn.

Equations

Alter alias x1 ((alias ::: x0) ': xs) = (alias ::: x1) ': xs 
Alter alias x1 (x0 ': xs) = x0 ': Alter alias x1 xs 

type family Rename alias0 alias1 xs where ... Source #

Rename alias0 alias1 xs replaces the alias alias0 by alias1 in xs and is used in alterTableRename and renameColumn.

Equations

Rename alias0 alias1 ((alias0 ::: x0) ': xs) = (alias1 ::: x0) ': xs 
Rename alias0 alias1 (x ': xs) = x ': Rename alias0 alias1 xs 

type family Elem x xs where ... Source #

Elem is a promoted elem.

Equations

Elem x '[] = False 
Elem x (x ': xs) = True 
Elem x (_ ': xs) = Elem x xs 

type family In x xs :: Constraint where ... Source #

In x xs is a constraint that proves that x is in xs.

Equations

In x xs = Elem x xs ~ True 

type PGNum ty = In ty '[PGint2, PGint4, PGint8, PGnumeric, PGfloat4, PGfloat8] Source #

PGNum is a constraint on PGType whose Expressions have a Num constraint.

type PGIntegral ty = In ty '[PGint2, PGint4, PGint8] Source #

PGIntegral is a constraint on PGType whose Expressions have div_ and mod_ functions.

type PGFloating ty = In ty '[PGfloat4, PGfloat8, PGnumeric] Source #

PGFloating is a constraint on PGType whose Expressions have Fractional and Floating constraints.

type family PGTypeOf (ty :: NullityType) :: PGType where ... Source #

PGTypeOf forgets about NULL and any column constraints.

Equations

PGTypeOf (nullity pg) = pg 

type family SameTypes (columns0 :: ColumnsType) (columns1 :: ColumnsType) :: Constraint where ... Source #

SameTypes is a constraint that proves two ColumnsTypes have the same length and the same ColumnTypes.

Equations

SameTypes '[] '[] = () 
SameTypes ((column0 ::: (def0 :=> ty0)) ': columns0) ((column1 ::: (def1 :=> ty1)) ': columns1) = (ty0 ~ ty1, SameTypes columns0 columns1) 

class SamePGType (ty0 :: (Symbol, ColumnType)) (ty1 :: (Symbol, ColumnType)) Source #

Equality constraint on the underlying PGType of two columns.

Instances

(~) k ty0 ty1 => SamePGType ((:::) (ColumnConstraint, NullityType) alias0 ((:=>) ColumnConstraint NullityType def0 (nullity0 ty0))) ((:::) (ColumnConstraint, NullityType) alias1 ((:=>) ColumnConstraint NullityType def1 (nullity1 ty1))) Source # 

type family AllNotNull (columns :: ColumnsType) :: Constraint where ... Source #

AllNotNull is a constraint that proves a ColumnsType has no NULLs.

Equations

AllNotNull '[] = () 
AllNotNull ((column ::: (def :=> NotNull ty)) ': columns) = AllNotNull columns 

type family NotAllNull (columns :: ColumnsType) :: Constraint where ... Source #

NotAllNull is a constraint that proves a ColumnsType has some NOT NULL.

Equations

NotAllNull ((column ::: (def :=> NotNull ty)) ': columns) = () 
NotAllNull ((column ::: (def :=> Null ty)) ': columns) = NotAllNull columns 

type family NullifyType (ty :: NullityType) :: NullityType where ... Source #

NullifyType is an idempotent that nullifies a ColumnType.

Equations

NullifyType (Null ty) = Null ty 
NullifyType (NotNull ty) = Null ty 

type family NullifyRelation (columns :: RelationType) :: RelationType where ... Source #

NullifyRelation is an idempotent that nullifies a ColumnsType.

Equations

NullifyRelation '[] = '[] 
NullifyRelation ((column ::: ty) ': columns) = (column ::: NullifyType ty) ': NullifyRelation columns 

type family NullifyRelations (tables :: RelationsType) :: RelationsType where ... Source #

NullifyRelations is an idempotent that nullifies a RelationsType used to nullify the left or right hand side of an outer join in a FromClause.

Equations

NullifyRelations '[] = '[] 
NullifyRelations ((table ::: columns) ': tables) = (table ::: NullifyRelation columns) ': NullifyRelations tables 

type family ColumnsToRelation (columns :: ColumnsType) :: RelationType where ... Source #

ColumnsToRelation removes column constraints.

Equations

ColumnsToRelation '[] = '[] 
ColumnsToRelation ((column ::: (constraint :=> ty)) ': columns) = (column ::: ty) ': ColumnsToRelation columns 

type family TableToColumns (table :: TableType) :: ColumnsType where ... Source #

TableToColumns removes table constraints.

Equations

TableToColumns (constraints :=> columns) = columns 

type family TableToRelation (table :: TableType) :: RelationType where ... Source #

Convert a table to a relation.

type family ConstraintInvolves column constraint where ... Source #

Check if a TableConstraint involves a column

Equations

ConstraintInvolves column (Check columns) = column `Elem` columns 
ConstraintInvolves column (Unique columns) = column `Elem` columns 
ConstraintInvolves column (PrimaryKey columns) = column `Elem` columns 
ConstraintInvolves column (ForeignKey columns tab refcolumns) = column `Elem` columns 

type family DropIfConstraintsInvolve column constraints where ... Source #

Drop all TableConstraints that involve a column

Equations

DropIfConstraintsInvolve column '[] = '[] 
DropIfConstraintsInvolve column ((alias ::: constraint) ': constraints) = If (ConstraintInvolves column constraint) (DropIfConstraintsInvolve column constraints) ((alias ::: constraint) ': DropIfConstraintsInvolve column constraints) 

Embedding

type family PG (hask :: Type) :: PGType where ... Source #

The PG type family embeds a subset of Haskell types as Postgres basic types.

>>> :kind! PG LocalTime
PG LocalTime :: PGType
= 'PGtimestamp

type family EnumFrom (hask :: Type) :: PGType where ... Source #

The EnumFrom type family embeds Haskell enum types, ADTs with nullary constructors, as Postgres enum types

>>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
>>> instance Generic Schwarma
>>> instance HasDatatypeInfo Schwarma
>>> :kind! EnumFrom Schwarma
EnumFrom Schwarma :: PGType
= 'PGenum '["Beef", "Lamb", "Chicken"]

Equations

EnumFrom hask = PGenum (LabelsFrom hask) 

type family LabelsFrom (hask :: Type) :: [ConstructorName] where ... Source #

The LabelsFrom type family calculates the constructors of a Haskell enum type.

>>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
>>> instance Generic Schwarma
>>> instance HasDatatypeInfo Schwarma
>>> :kind! LabelsFrom Schwarma
LabelsFrom Schwarma :: [Type.ConstructorName]
= '["Beef", "Lamb", "Chicken"]

type family CompositeFrom (hask :: Type) :: PGType where ... Source #

The CompositeFrom type family embeds Haskell record types as Postgres composite types, as long as the record fields are Maybes of Haskell types that can be embedded as basic types with the PG type family.

>>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
>>> instance Generic Row
>>> instance HasDatatypeInfo Row
>>> :kind! CompositeFrom Row
CompositeFrom Row :: PGType
= 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]

Equations

CompositeFrom hask = PGcomposite (ZipAs (FieldNamesFrom hask) (FieldTypesFrom hask)) 

type family FieldNamesFrom (hask :: Type) :: [FieldName] where ... Source #

>>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
>>> instance Generic Row
>>> instance HasDatatypeInfo Row
>>> :kind! FieldNamesFrom Row
FieldNamesFrom Row :: [Type.FieldName]
= '["a", "b"]

type family FieldTypesFrom (hask :: Type) :: [PGType] where ... Source #

>>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
>>> instance Generic Row
>>> instance HasDatatypeInfo Row
>>> :kind! FieldTypesFrom Row
FieldTypesFrom Row :: [PGType]
= '['PGint2, 'PGtimestamp]

Equations

FieldTypesFrom hask = FieldTypesOf (RecordCodeOf hask (Code hask)) 

type family ConstructorsOf (datatype :: DatatypeInfo) :: [ConstructorInfo] where ... Source #

Calculates constructors of a datatype.

Equations

ConstructorsOf (ADT _module _datatype constructors) = constructors 
ConstructorsOf (Newtype _module _datatype constructor) = '[constructor] 

type family ConstructorNameOf (constructors :: ConstructorInfo) :: ConstructorName where ... Source #

Calculates the name of a nullary constructor, otherwise generates a type error.

Equations

ConstructorNameOf (Constructor name) = name 
ConstructorNameOf (Infix name _assoc _fix) = TypeError (Text "ConstructorNameOf error: non-nullary constructor " :<>: Text name) 
ConstructorNameOf (Record name _fields) = TypeError (Text "ConstructorNameOf error: non-nullary constructor " :<>: Text name) 

type family ConstructorNamesOf (constructors :: [ConstructorInfo]) :: [ConstructorName] where ... Source #

Calculate the names of nullary constructors.

Equations

ConstructorNamesOf '[] = '[] 
ConstructorNamesOf (constructor ': constructors) = ConstructorNameOf constructor ': ConstructorNamesOf constructors 

type family FieldsOf (datatype :: DatatypeInfo) :: [FieldInfo] where ... Source #

Calculate the fields of a datatype.

Equations

FieldsOf (ADT _module _datatype '[Record _name fields]) = fields 
FieldsOf (Newtype _module _datatype (Record _name fields)) = fields 

type family FieldNameOf (field :: FieldInfo) :: FieldName where ... Source #

Calculate the name of a field.

Equations

FieldNameOf (FieldInfo name) = name 

type family FieldNamesOf (fields :: [FieldInfo]) :: [FieldName] where ... Source #

Calculate the names of fields.

Equations

FieldNamesOf '[] = '[] 
FieldNamesOf (field ': fields) = FieldNameOf field ': FieldNamesOf fields 

type family FieldTypeOf (maybe :: Type) where ... Source #

>>> :kind! FieldTypeOf (Maybe Int16)
FieldTypeOf (Maybe Int16) :: PGType
= 'PGint2

Equations

FieldTypeOf (Maybe hask) = PG hask 
FieldTypeOf ty = TypeError (Text "FieldTypeOf error: non-Maybe type " :<>: ShowType ty) 

type family FieldTypesOf (fields :: [Type]) where ... Source #

Calculate the types of fields.

Equations

FieldTypesOf '[] = '[] 
FieldTypesOf (field ': fields) = FieldTypeOf field ': FieldTypesOf fields 

type family RecordCodeOf (hask :: Type) (code :: [[Type]]) :: [Type] where ... Source #

Inspect the code of an algebraic datatype and ensure it's a product, otherwise generate a type error

Equations

RecordCodeOf _hask '[tys] = tys 
RecordCodeOf hask _tys = TypeError (Text "RecordCodeOf error: non-Record type " :<>: ShowType hask) 

class MapMaybes xs where Source #

MapMaybes is used in the binary instances of composite types.

Minimal complete definition

maybes, unMaybes

Associated Types

type Maybes (xs :: [Type]) = (mxs :: [Type]) | mxs -> xs Source #

Methods

maybes :: NP Maybe xs -> NP I (Maybes xs) Source #

unMaybes :: NP I (Maybes xs) -> NP Maybe xs Source #

Instances

MapMaybes ([] Type) Source # 

Associated Types

type Maybes ([Type] :: [Type]) = (mxs :: [Type]) Source #

MapMaybes xs => MapMaybes ((:) Type x xs) Source # 

Associated Types

type Maybes ((Type ': x) xs :: [Type]) = (mxs :: [Type]) Source #

Methods

maybes :: NP * Maybe ((Type ': x) xs) -> NP * I (Maybes ((Type ': x) xs)) Source #

unMaybes :: NP * I (Maybes ((Type ': x) xs)) -> NP * Maybe ((Type ': x) xs) Source #

type family Nulls tys where ... Source #

Nulls is used to construct a row of a composite type.

Equations

Nulls '[] = '[] 
Nulls ((field ::: ty) ': tys) = (field ::: Null ty) ': Nulls tys