Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Schema
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
- data PGType
- = PGbool
- | PGint2
- | PGint4
- | PGint8
- | PGnumeric
- | PGfloat4
- | PGfloat8
- | PGmoney
- | PGchar Nat
- | PGvarchar Nat
- | PGtext
- | PGbytea
- | PGtimestamp
- | PGtimestamptz
- | PGdate
- | PGtime
- | PGtimetz
- | PGinterval
- | PGuuid
- | PGinet
- | PGjson
- | PGjsonb
- | PGvararray NullityType
- | PGfixarray [Nat] NullityType
- | PGenum [Symbol]
- | PGcomposite RowType
- | PGtsvector
- | PGtsquery
- | UnsafePGType Symbol
- data NullityType
- type RowType = [(Symbol, NullityType)]
- type FromType = [(Symbol, RowType)]
- type ColumnType = (ColumnConstraint, NullityType)
- type ColumnsType = [(Symbol, ColumnType)]
- type TableType = (TableConstraints, ColumnsType)
- data SchemumType
- type SchemaType = [(Symbol, SchemumType)]
- type SchemasType = [(Symbol, SchemaType)]
- type family Public (schema :: SchemaType) :: SchemasType where ...
- type (:=>) constraint ty = '(constraint, ty)
- data ColumnConstraint
- data TableConstraint
- = Check [Symbol]
- | Unique [Symbol]
- | PrimaryKey [Symbol]
- | ForeignKey [Symbol] Symbol [Symbol]
- type TableConstraints = [(Symbol, TableConstraint)]
- type family Uniquely (key :: [Symbol]) (constraints :: TableConstraints) :: Constraint where ...
- class IsPGlabel (label :: Symbol) expr where
- label :: expr
- data PGlabel (label :: Symbol) = PGlabel
- type family Create alias x xs where ...
- type family Drop alias xs where ...
- type family Alter alias x xs where ...
- type family Rename alias0 alias1 xs where ...
- type family ConstraintInvolves column constraint where ...
- type family DropIfConstraintsInvolve column constraints where ...
- class IsNotElem x isElem
- class AllUnique (xs :: [(Symbol, a)])
- type PGNum = '[PGint2, PGint4, PGint8, PGnumeric, PGfloat4, PGfloat8]
- type PGIntegral = '[PGint2, PGint4, PGint8]
- type PGFloating = '[PGfloat4, PGfloat8, PGnumeric]
- type family PGTypeOf (ty :: NullityType) :: PGType where ...
- type PGJsonType = '[PGjson, PGjsonb]
- type PGJsonKey = '[PGint2, PGint4, PGtext]
- class SamePGType (ty0 :: (Symbol, ColumnType)) (ty1 :: (Symbol, ColumnType))
- type family AllNotNull (columns :: ColumnsType) :: Constraint where ...
- type family NotAllNull (columns :: ColumnsType) :: Constraint where ...
- type family NullifyType (ty :: NullityType) :: NullityType where ...
- type family NullifyRow (columns :: RowType) :: RowType where ...
- type family NullifyFrom (tables :: FromType) :: FromType where ...
- type family TableToColumns (table :: TableType) :: ColumnsType where ...
- type family ColumnsToRow (columns :: ColumnsType) :: RowType where ...
- type family TableToRow (table :: TableType) :: RowType where ...
Postgres Types
PGType
is the promoted datakind of PostgreSQL types.
>>>
:kind 'PGbool
'PGbool :: PGType
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) |
PGmoney | currency amount |
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 NullityType | variable length array |
PGfixarray [Nat] NullityType | fixed length array |
PGenum [Symbol] | enumerated (enum) types are data types that comprise a static, ordered set of values. |
PGcomposite RowType | a composite type represents the structure of a row or record; it is essentially just a list of field names and their data types. |
PGtsvector | A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word. |
PGtsquery | A tsquery value stores lexemes that are to be searched for |
UnsafePGType Symbol | an escape hatch for unsupported PostgreSQL types |
Instances
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
Instances
(Has tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullityType)]))) => IsQualified tab col (NP (Aliased (Expression outer commons (Grouped bys) schemas params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression outer commons (Grouped bys) schemas params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullityType]))) => IsQualified tab col (NP (Expression outer commons (Grouped bys) schemas params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join outer from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullityType)]))) => IsQualified tab col (NP (Aliased (Expression outer commons Ungrouped schemas params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join outer from) row, Has col row ty, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression outer commons Ungrouped schemas params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join outer from) row, Has col row ty, tys ~ (ty ': ([] :: [NullityType]))) => IsQualified tab col (NP (Expression outer commons Ungrouped schemas params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
Aggregate (Distinction (Expression outer commons Ungrouped schemas params from)) (Distinction (NP (Expression outer commons Ungrouped schemas params from)) :: [NullityType] -> Type) (Expression outer commons (Grouped bys) schemas params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate countStar :: Expression outer commons (Grouped bys) schemas params from (NotNull PGint8) Source # count :: Distinction (Expression outer commons Ungrouped schemas params from) ty -> Expression outer commons (Grouped bys) schemas params from (NotNull PGint8) Source # sum_ :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGSum ty)) Source # arrayAgg :: Distinction (Expression outer commons Ungrouped schemas params from) ty -> Expression outer commons (Grouped bys) schemas params from (Null (PGvararray ty)) Source # jsonAgg :: Distinction (Expression outer commons Ungrouped schemas params from) ty -> Expression outer commons (Grouped bys) schemas params from (Null PGjson) Source # jsonbAgg :: Distinction (Expression outer commons Ungrouped schemas params from) ty -> Expression outer commons (Grouped bys) schemas params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => Distinction (Expression outer commons Ungrouped schemas params from) (null int) -> Expression outer commons (Grouped bys) schemas params from (Null int) Source # bitOr :: In int PGIntegral => Distinction (Expression outer commons Ungrouped schemas params from) (null int) -> Expression outer commons (Grouped bys) schemas params from (Null int) Source # boolAnd :: Distinction (Expression outer commons Ungrouped schemas params from) (null PGbool) -> Expression outer commons (Grouped bys) schemas params from (Null PGbool) Source # boolOr :: Distinction (Expression outer commons Ungrouped schemas params from) (null PGbool) -> Expression outer commons (Grouped bys) schemas params from (Null PGbool) Source # every :: Distinction (Expression outer commons Ungrouped schemas params from) (null PGbool) -> Expression outer commons (Grouped bys) schemas params from (Null PGbool) Source # max_ :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null ty) Source # min_ :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null ty) Source # avg :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # corr :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # covarPop :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # covarSamp :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrAvgX :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrAvgY :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrCount :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGint8) Source # regrIntercept :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrR2 :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrSlope :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrSxx :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrSxy :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # regrSyy :: Distinction (NP (Expression outer commons Ungrouped schemas params from)) (null PGfloat8 ': (null PGfloat8 ': [])) -> Expression outer commons (Grouped bys) schemas params from (Null PGfloat8) Source # stddev :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # stddevPop :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # stddevSamp :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # variance :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # varPop :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # varSamp :: Distinction (Expression outer commons Ungrouped schemas params from) (null ty) -> Expression outer commons (Grouped bys) schemas params from (Null (PGAvg ty)) Source # | |
(HasUnique tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullityType)]))) => IsLabel col (NP (Aliased (Expression outer commons (Grouped bys) schemas params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression outer commons (Grouped bys) schemas params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression outer commons (Grouped bys) schemas params from) column # | |
(HasUnique tab (Join outer from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullityType]))) => IsLabel col (NP (Expression outer commons (Grouped bys) schemas params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression outer commons (Grouped bys) schemas params from) tys # | |
(HasUnique tab (Join outer from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullityType)]))) => IsLabel col (NP (Aliased (Expression outer commons Ungrouped schemas params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join outer from) row, Has col row ty, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression outer commons Ungrouped schemas params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression outer commons Ungrouped schemas params from) column # | |
(HasUnique tab (Join outer from) row, Has col row ty, tys ~ (ty ': ([] :: [NullityType]))) => IsLabel col (NP (Expression outer commons Ungrouped schemas params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression outer commons Ungrouped schemas params from) tys # | |
(KnownSymbol alias, PGTyped schemas ty) => FieldTyped schemas (alias ::: ty) Source # | |
Defined in Squeal.PostgreSQL.Definition | |
(KnownNat n, HasParameter (n - 1) params ty) => HasParameter n (ty' ': params) ty Source # | |
Defined in Squeal.PostgreSQL.Expression.Parameter parameter :: TypeExpression schemas ty -> Expression outer commons grp schemas (ty' ': params) from ty Source # | |
HasParameter 1 (ty1 ': tys) ty1 Source # | |
Defined in Squeal.PostgreSQL.Expression.Parameter parameter :: TypeExpression schemas ty1 -> Expression outer commons grp schemas (ty1 ': tys) from ty1 Source # | |
(KnownSymbol cte, commons1 ~ ((cte ::: common) ': commons)) => Aliasable cte (statement commons schemas params common) (AlignedList (CommonTableExpression statement schemas params) commons commons1) Source # | |
Defined in Squeal.PostgreSQL.Query as :: statement commons schemas params common -> Alias cte -> AlignedList (CommonTableExpression statement schemas params) commons commons1 Source # | |
Aggregate (Expression outer commons grp schemas params from) (NP (Expression outer commons grp schemas params from) :: [NullityType] -> Type) (WindowFunction outer commons grp schemas params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Window countStar :: WindowFunction outer commons grp schemas params from (NotNull PGint8) Source # count :: Expression outer commons grp schemas params from ty -> WindowFunction outer commons grp schemas params from (NotNull PGint8) Source # sum_ :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGSum ty)) Source # arrayAgg :: Expression outer commons grp schemas params from ty -> WindowFunction outer commons grp schemas params from (Null (PGvararray ty)) Source # jsonAgg :: Expression outer commons grp schemas params from ty -> WindowFunction outer commons grp schemas params from (Null PGjson) Source # jsonbAgg :: Expression outer commons grp schemas params from ty -> WindowFunction outer commons grp schemas params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => Expression outer commons grp schemas params from (null int) -> WindowFunction outer commons grp schemas params from (Null int) Source # bitOr :: In int PGIntegral => Expression outer commons grp schemas params from (null int) -> WindowFunction outer commons grp schemas params from (Null int) Source # boolAnd :: Expression outer commons grp schemas params from (null PGbool) -> WindowFunction outer commons grp schemas params from (Null PGbool) Source # boolOr :: Expression outer commons grp schemas params from (null PGbool) -> WindowFunction outer commons grp schemas params from (Null PGbool) Source # every :: Expression outer commons grp schemas params from (null PGbool) -> WindowFunction outer commons grp schemas params from (Null PGbool) Source # max_ :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null ty) Source # min_ :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null ty) Source # avg :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # corr :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # covarPop :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # covarSamp :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrAvgX :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrAvgY :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrCount :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGint8) Source # regrIntercept :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrR2 :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrSlope :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrSxx :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrSxy :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # regrSyy :: NP (Expression outer commons grp schemas params from) (null PGfloat8 ': (null PGfloat8 ': [])) -> WindowFunction outer commons grp schemas params from (Null PGfloat8) Source # stddev :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # stddevPop :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # stddevSamp :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # variance :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # varPop :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # varSamp :: Expression outer commons grp schemas params from (null ty) -> WindowFunction outer commons grp schemas params from (Null (PGAvg ty)) Source # | |
JsonBuildObject ([] :: [NullityType]) Source # | |
Defined in Squeal.PostgreSQL.Expression.Json jsonBuildObject :: FunctionN [] (null PGjson) Source # jsonbBuildObject :: FunctionN [] (null PGjsonb) Source # | |
Additional (Selection outer commons grp schemas params from :: RowType -> Type) Source # | |
NFData (Distinction (Expression outer commons grp schemas params from) ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate rnf :: Distinction (Expression outer commons grp schemas params from) ty -> () # | |
SListI tys => RenderSQL (Distinction (NP (Expression outer commons grp schemas params from)) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate renderSQL :: Distinction (NP (Expression outer commons grp schemas params from)) tys -> ByteString Source # | |
RenderSQL (Distinction (Expression outer commons grp schemas params from) ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate renderSQL :: Distinction (Expression outer commons grp schemas params from) ty -> ByteString Source # | |
(JsonBuildObject tys, In key PGJsonKey) => JsonBuildObject (NotNull key ': (value ': tys)) Source # | |
Defined in Squeal.PostgreSQL.Expression.Json | |
HasOid ty => HasAliasedOid (alias ::: nullity ty) Source # | |
Defined in Squeal.PostgreSQL.Binary aliasedOid :: Word32 Source # | |
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> nullity0 ty0)) (alias1 ::: (def1 :=> nullity1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Schema | |
FromValue pg y => FromField (column ::: Null pg) (column ::: Maybe y) Source # | |
FromValue pg y => FromField (column ::: NotNull pg) (column ::: y) Source # | |
ToNullityParam x ty => ToField (alias ::: x) (alias ::: ty) Source # | |
AddColumn (Def :=> ty) Source # | |
Defined in Squeal.PostgreSQL.Definition | |
AddColumn (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Definition | |
IsString (Selection outer commons grp schemas params from (("fromOnly" ::: NotNull PGtext) ': ([] :: [(Symbol, NullityType)]))) Source # | |
Defined in Squeal.PostgreSQL.Query |
type RowType = [(Symbol, NullityType)] Source #
A RowType
is a row of NullityType
. They correspond to Haskell
record types by means of RowPG
and are used in many places.
>>>
:{
type family PersonRow :: RowType where PersonRow = '[ "name" ::: 'NotNull 'PGtext , "age" ::: 'NotNull 'PGint4 , "dateOfBirth" ::: 'Null 'PGdate ] :}
type FromType = [(Symbol, RowType)] Source #
FromType
is a row of RowType
s. It can be thought of as
a product, or horizontal gluing and is used in FromClause
s
and TableExpression
s.
Schema Types
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
type ColumnsType = [(Symbol, ColumnType)] Source #
ColumnsType
is a row of ColumnType
s.
>>>
:{
type family UsersColumns :: ColumnsType where UsersColumns = '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext , "id" ::: 'Def :=> 'NotNull 'PGint4 ] :}
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 ] :}
data SchemumType Source #
A SchemumType
is a user-defined type, either a Table
,
View
or Typedef
.
Instances
Category Definition Source # | |
Defined in Squeal.PostgreSQL.Definition id :: Definition a a # (.) :: Definition b c -> Definition a b -> Definition a c # | |
(IndexedMonadTransPQ trans, Monad monad, forall (x0 :: SchemasType) (x1 :: SchemasType). x0 ~ x1 => Monad (trans x0 x1 monad)) => Category (Terminally trans monad :: SchemasType -> SchemasType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Migration id :: Terminally trans monad a a # (.) :: Terminally trans monad b c -> Terminally trans monad a b -> Terminally trans monad a c # | |
Migratory (Terminally PQ IO) Source # | |
Defined in Squeal.PostgreSQL.Migration migrateUp :: AlignedList (Migration (Terminally PQ IO)) schemas0 schemas1 -> PQ schemas0 schemas1 IO () Source # migrateDown :: AlignedList (Migration (Terminally PQ IO)) schemas0 schemas1 -> PQ schemas1 schemas0 IO () Source # |
type SchemaType = [(Symbol, SchemumType)] Source #
The schema of a database consists of a list of aliased,
user-defined SchemumType
s.
>>>
:{
type family Schema :: SchemaType where Schema = '[ "users" ::: 'Table ( '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=> '[ "id" ::: 'Def :=> 'NotNull 'PGint4 , "name" ::: 'NoDef :=> 'NotNull 'PGtext ]) , "emails" ::: 'Table ( '[ "pk_emails" ::: 'PrimaryKey '["id"] , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ] :=> '[ "id" ::: 'Def :=> 'NotNull 'PGint4 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4 , "email" ::: 'NoDef :=> 'Null 'PGtext ]) ] :}
type SchemasType = [(Symbol, SchemaType)] Source #
A database contains one or more named schemas, which in turn contain tables. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database they are connected to, if they have privileges to do so.
There are several reasons why one might want to use schemas:
- To allow many users to use one database without interfering with each other.
- To organize database objects into logical groups to make them more manageable.
- Third-party applications can be put into separate schemas so they do not collide with the names of other objects.
type family Public (schema :: SchemaType) :: SchemasType where ... Source #
A type family to use for a single schema database.
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.
Instances
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> nullity0 ty0)) (alias1 ::: (def1 :=> nullity1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Schema | |
AddColumn (Def :=> ty) Source # | |
Defined in Squeal.PostgreSQL.Definition | |
AddColumn (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Definition |
data TableConstraint Source #
TableConstraint
encodes various forms of data constraints
of columns in a table.
TableConstraint
s 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.
Check [Symbol] | |
Unique [Symbol] | |
PrimaryKey [Symbol] | |
ForeignKey [Symbol] Symbol [Symbol] |
Instances
SListI (TableToColumns table) => RenderSQL (ConflictClause tab commons schemas params table) Source # | Render a |
Defined in Squeal.PostgreSQL.Manipulation renderSQL :: ConflictClause tab commons schemas params table -> ByteString Source # |
type TableConstraints = [(Symbol, TableConstraint)] Source #
A TableConstraints
is a row of TableConstraint
s.
>>>
:{
type family UsersConstraints :: TableConstraints where UsersConstraints = '[ "pk_users" ::: 'PrimaryKey '["id"] ] :}
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.
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,
label
s are used for enum terms. A label
is called with
type application like `label @"beef"`.
Instances
label ~ label1 => IsPGlabel label (PGlabel label1) Source # | |
Defined in Squeal.PostgreSQL.Schema | |
labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # | |
(KnownSymbol label, In label labels) => IsPGlabel label (Expression outer commons grp schemas params from (null (PGenum labels))) Source # | |
Defined in Squeal.PostgreSQL.Expression label :: Expression outer commons grp schemas params from (null (PGenum labels)) Source # |
data PGlabel (label :: Symbol) Source #
Instances
label ~ label1 => IsPGlabel label (PGlabel label1) Source # | |
Defined in Squeal.PostgreSQL.Schema | |
labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # | |
KnownSymbol label => RenderSQL (PGlabel label) Source # | |
Defined in Squeal.PostgreSQL.Schema renderSQL :: PGlabel label -> ByteString Source # | |
All KnownSymbol labels => RenderSQL (NP PGlabel labels) Source # | |
Defined in Squeal.PostgreSQL.Schema |
Data Definitions
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
.
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.
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
.
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
.
type family ConstraintInvolves column constraint where ... Source #
Check if a TableConstraint
involves a column
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 TableConstraint
s that involve a column
DropIfConstraintsInvolve column '[] = '[] | |
DropIfConstraintsInvolve column ((alias ::: constraint) ': constraints) = If (ConstraintInvolves column constraint) (DropIfConstraintsInvolve column constraints) ((alias ::: constraint) ': DropIfConstraintsInvolve column constraints) |
class AllUnique (xs :: [(Symbol, a)]) Source #
No elem of xs
appears more than once, in the context of assignment.
Type Classifications
type PGNum = '[PGint2, PGint4, PGint8, PGnumeric, PGfloat4, PGfloat8] Source #
Numeric Postgres types.
type family PGTypeOf (ty :: NullityType) :: PGType where ... Source #
PGTypeOf
forgets about NULL
and any column constraints.
PGTypeOf (nullity pg) = pg |
type PGJsonType = '[PGjson, PGjsonb] Source #
Is a type a valid JSON type?
class SamePGType (ty0 :: (Symbol, ColumnType)) (ty1 :: (Symbol, ColumnType)) Source #
Equality constraint on the underlying PGType
of two columns.
Instances
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> nullity0 ty0)) (alias1 ::: (def1 :=> nullity1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Schema |
type family AllNotNull (columns :: ColumnsType) :: Constraint where ... Source #
AllNotNull
is a constraint that proves a ColumnsType
has no NULL
s.
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
.
NotAllNull ((column ::: (def :=> NotNull ty)) ': columns) = () | |
NotAllNull ((column ::: (def :=> Null ty)) ': columns) = NotAllNull columns |
Nullifications
type family NullifyType (ty :: NullityType) :: NullityType where ... Source #
NullifyType
is an idempotent that nullifies a NullityType
.
NullifyType (Null ty) = Null ty | |
NullifyType (NotNull ty) = Null ty |
type family NullifyRow (columns :: RowType) :: RowType where ... Source #
NullifyRow
is an idempotent that nullifies a RowType
.
NullifyRow '[] = '[] | |
NullifyRow ((column ::: ty) ': columns) = (column ::: NullifyType ty) ': NullifyRow columns |
type family NullifyFrom (tables :: FromType) :: FromType where ... Source #
NullifyFrom
is an idempotent that nullifies a FromType
used to nullify the left or right hand side of an outer join
in a FromClause
.
NullifyFrom '[] = '[] | |
NullifyFrom ((table ::: columns) ': tables) = (table ::: NullifyRow columns) ': NullifyFrom tables |
Table Conversions
type family TableToColumns (table :: TableType) :: ColumnsType where ... Source #
TableToColumns
removes table constraints.
TableToColumns (constraints :=> columns) = columns |
type family ColumnsToRow (columns :: ColumnsType) :: RowType where ... Source #
ColumnsToRow
removes column constraints.
ColumnsToRow '[] = '[] | |
ColumnsToRow ((column ::: (constraint :=> ty)) ': columns) = (column ::: ty) ': ColumnsToRow columns |
type family TableToRow (table :: TableType) :: RowType where ... Source #
Convert a table to a row type.
TableToRow tab = ColumnsToRow (TableToColumns tab) |