Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Squeal.PostgreSQL.Type.Schema
Contents
Description
Schema
provides a type-level DSL
for kinds of Postgres types, tables, schema, constraints, and more.
It also defines useful type families to operate on these.
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 NullType
- | PGfixarray [Nat] NullType
- | PGenum [Symbol]
- | PGcomposite RowType
- | PGtsvector
- | PGtsquery
- | PGoid
- | PGrange PGType
- | UnsafePGType Symbol
- data NullType
- type RowType = [(Symbol, NullType)]
- type FromType = [(Symbol, RowType)]
- type ColumnType = (Optionality, NullType)
- type ColumnsType = [(Symbol, ColumnType)]
- type TableType = (TableConstraints, ColumnsType)
- data SchemumType
- data IndexType
- type FunctionType = ([NullType], ReturnsType)
- data ReturnsType
- type SchemaType = [(Symbol, SchemumType)]
- type SchemasType = [(Symbol, SchemaType)]
- type family Public (schema :: SchemaType) :: SchemasType where ...
- type (:=>) constraint ty = '(constraint, ty)
- data Optionality
- 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 CreateIfNotExists alias x xs where ...
- type family CreateOrReplace alias x xs where ...
- type family Drop alias xs where ...
- type family DropSchemum alias sch xs where ...
- type family DropIfExists alias xs where ...
- type family DropSchemumIfExists alias sch xs where ...
- type family Alter alias x xs where ...
- type family AlterIfExists alias x xs where ...
- type family Rename alias0 alias1 xs where ...
- type family RenameIfExists alias0 alias1 xs where ...
- type family ConstraintInvolves column constraint where ...
- type family DropIfConstraintsInvolve column constraints where ...
- type PGNum = '[PGint2, PGint4, PGint8, PGnumeric, PGfloat4, PGfloat8]
- type PGIntegral = '[PGint2, PGint4, PGint8]
- type PGFloating = '[PGfloat4, PGfloat8, PGnumeric]
- type family PGTypeOf (ty :: NullType) :: 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 :: NullType) :: NullType 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 ...
- type Updatable table columns = (All (HasIn (TableToColumns table)) columns, AllUnique columns, SListI (TableToColumns table))
- class AllUnique (xs :: [(Symbol, a)])
- class IsNotElem x isElem
- type family UserType (db :: SchemasType) (ty :: PGType) where ...
- type family UserTypeName (schema :: SchemaType) (ty :: PGType) where ...
- type family UserTypeNamespace (sch :: Symbol) (td :: Maybe Symbol) (schemas :: SchemasType) (ty :: PGType) where ...
Postgres Type
PGType
is the promoted datakind of PostgreSQL types.
>>>
: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) |
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 NullType | variable length array |
PGfixarray [Nat] NullType | 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. |
PGoid | |
PGrange PGType | Range types are data types representing a range of values of some element type (called the range's subtype). |
UnsafePGType Symbol | an escape hatch for unsupported PostgreSQL types |
Instances
NullType
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 :: NullType>>>
:kind 'NotNull ('PGvarchar 50)
'NotNull ('PGvarchar 50) :: NullType
Instances
Aggregate AggregateArg (Expression (Grouped bys) :: FromType -> FromType -> SchemasType -> [NullType] -> FromType -> NullType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate Methods countStar :: Expression (Grouped bys) lat with db params from (NotNull PGint8) Source # count :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (NotNull PGint8) Source # sum_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGSum ty)) Source # arrayAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGvararray ty)) Source # jsonAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGjson) Source # jsonbAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => AggregateArg (null int ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null int) Source # bitOr :: In int PGIntegral => AggregateArg (null int ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null int) Source # boolAnd :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # boolOr :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # every :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # max_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null ty) Source # min_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null ty) Source # avg :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # corr :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # covarPop :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # covarSamp :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrAvgX :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrAvgY :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrCount :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGint8) Source # regrIntercept :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrR2 :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSlope :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSxx :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSxy :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSyy :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # stddev :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # stddevPop :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # stddevSamp :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # variance :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # varPop :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # varSamp :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # | |
Aggregate (WindowArg grp :: [NullType] -> FromType -> FromType -> SchemasType -> [NullType] -> FromType -> Type) (WindowFunction grp :: FromType -> FromType -> SchemasType -> [NullType] -> FromType -> NullType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Expression.Window Methods countStar :: WindowFunction grp lat with db params from (NotNull PGint8) Source # count :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (NotNull PGint8) Source # sum_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGSum ty)) Source # arrayAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGvararray ty)) Source # jsonAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGjson) Source # jsonbAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => WindowArg grp (null int ': []) lat with db params from -> WindowFunction grp lat with db params from (Null int) Source # bitOr :: In int PGIntegral => WindowArg grp (null int ': []) lat with db params from -> WindowFunction grp lat with db params from (Null int) Source # boolAnd :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # boolOr :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # every :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # max_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null ty) Source # min_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null ty) Source # avg :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # corr :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # covarPop :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # covarSamp :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrAvgX :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrAvgY :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrCount :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGint8) Source # regrIntercept :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrR2 :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSlope :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSxx :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSxy :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSyy :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # stddev :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # stddevPop :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # stddevSamp :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # variance :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # varPop :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # varSamp :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # | |
(Has tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsQualified tab col (NP (Aliased (Expression (Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression (Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullType]))) => IsQualified tab col (NP (Expression (Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsQualified tab col (NP (Aliased (Expression Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, tys ~ (ty ': ([] :: [NullType]))) => IsQualified tab col (NP (Expression Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
IsLabel fld (MaybeT (DecodeRow row) y) => IsLabel fld (MaybeT (DecodeRow (field ': row)) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
FromValue ty (Maybe y) => IsLabel fld (MaybeT (DecodeRow ((fld ::: ty) ': row)) y) Source # | |
IsLabel fld (DecodeRow row y) => IsLabel fld (DecodeRow (field ': row) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
FromValue ty y => IsLabel fld (DecodeRow ((fld ::: ty) ': row) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
(HasUnique tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsLabel col (NP (Aliased (Expression (Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression (Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression Methods fromLabel :: Aliased (Expression (Grouped bys) lat with db params from) column # | |
(HasUnique tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullType]))) => IsLabel col (NP (Expression (Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression Methods fromLabel :: NP (Expression (Grouped bys) lat with db params from) tys # | |
(HasUnique tab (Join lat from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsLabel col (NP (Aliased (Expression Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join lat from) row, Has col row ty, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression Methods fromLabel :: Aliased (Expression Ungrouped lat with db params from) column # | |
(HasUnique tab (Join lat from) row, Has col row ty, tys ~ (ty ': ([] :: [NullType]))) => IsLabel col (NP (Expression Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression Methods fromLabel :: NP (Expression Ungrouped lat with db params from) tys # | |
OidOfNull db ty => OidOfField db (fld ::: ty) Source # | |
Defined in Squeal.PostgreSQL.Session.Oid Methods oidOfField :: ReaderT (K Connection db) IO Oid Source # | |
(KnownSymbol alias, NullTyped db ty) => FieldTyped db (alias ::: ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Type | |
(KnownNat n, HasParameter (n - 1) params ty) => HasParameter n (ty' ': params) ty Source # | |
Defined in Squeal.PostgreSQL.Expression.Parameter Methods parameter :: TypeExpression db ty -> Expression grp lat with db (ty' ': params) from ty Source # | |
HasParameter 1 (ty1 ': tys) ty1 Source # | |
Defined in Squeal.PostgreSQL.Expression.Parameter Methods parameter :: TypeExpression db ty1 -> Expression grp lat with db (ty1 ': tys) from ty1 Source # | |
(fld0 ~ fld1, ToParam db ty x) => ToField db (fld0 ::: ty) (fld1 ::: x) Source # | |
NullTyped db (NotNull ty) => ColumnTyped db (NoDef :=> NotNull ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Type Methods columntype :: ColumnTypeExpression db (NoDef :=> NotNull ty) Source # | |
NullTyped db (Null ty) => ColumnTyped db (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Type Methods columntype :: ColumnTypeExpression db (NoDef :=> Null ty) Source # | |
(KnownSymbol cte, with1 ~ ((cte ::: common) ': with)) => Aliasable cte (statement with db params common) (Path (CommonTableExpression statement db params) with with1) Source # | |
Defined in Squeal.PostgreSQL.Query.With | |
JsonBuildObject ([] :: [NullType]) Source # | |
Defined in Squeal.PostgreSQL.Expression.Json Methods jsonBuildObject :: [] ---> null PGjson Source # jsonbBuildObject :: [] ---> null PGjsonb Source # | |
FilterWhere AggregateArg Ungrouped Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate Methods filterWhere :: Condition Ungrouped lat with db params from -> AggregateArg xs lat with db params from -> AggregateArg xs lat with db params from Source # | |
FilterWhere (WindowArg grp :: [NullType] -> FromType -> FromType -> SchemasType -> [NullType] -> FromType -> Type) grp Source # | |
Defined in Squeal.PostgreSQL.Expression.Window | |
Additional (FromClause lat with db params :: FromType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Query.From Methods also :: FromClause lat with db params ys -> FromClause lat with db params xs -> FromClause lat with db params (Join xs ys) Source # | |
Additional (Selection grp lat with db params from :: RowType -> Type) Source # | |
(JsonBuildObject tys, In key PGJsonKey) => JsonBuildObject (NotNull key ': (value ': tys)) Source # | |
Defined in Squeal.PostgreSQL.Expression.Json | |
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> null0 ty0)) (alias1 ::: (def1 :=> null1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema | |
(FromValue ty y, fld0 ~ fld1) => FromField (fld0 ::: ty) (fld1 ::: y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
(KnownSymbol col, InlineParam x ty) => InlineColumn (col ::: Optional I (Def :=> x)) (col ::: (Def :=> ty)) Source # | |
(KnownSymbol col, InlineParam x ty) => InlineColumn (col ::: x) (col ::: (NoDef :=> ty)) Source # | |
Defined in Squeal.PostgreSQL.Expression.Inline | |
(KnownSymbol alias, InlineParam x ty) => InlineField (alias ::: x) (alias ::: ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Inline Methods inlineField :: P (alias ::: x) -> Aliased (Expression grp lat with db params from) (alias ::: ty) Source # | |
AddColumn (Def :=> ty) Source # | |
Defined in Squeal.PostgreSQL.Definition.Table | |
AddColumn (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Definition.Table | |
IsString (Selection grp lat with db params from (("fromOnly" ::: NotNull PGtext) ': ([] :: [(Symbol, NullType)]))) Source # | |
Defined in Squeal.PostgreSQL.Query.Select |
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 Type
type ColumnType = (Optionality, NullType) 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
.
Constructors
Table TableType | |
View RowType | |
Typedef PGType | |
Index IndexType | |
Function FunctionType | |
UnsafeSchemum Symbol |
Instances
Category Definition Source # | |
Defined in Squeal.PostgreSQL.Definition | |
IndexedMonadTrans PQ Source # | |
Defined in Squeal.PostgreSQL.Session Methods pqAp :: Monad m => PQ i j m (x -> y) -> PQ j k m x -> PQ i k m y Source # pqJoin :: Monad m => PQ i j m (PQ j k m y) -> PQ i k m y Source # pqBind :: Monad m => (x -> PQ j k m y) -> PQ i j m x -> PQ i k m y Source # pqThen :: Monad m => PQ j k m y -> PQ i j m x -> PQ i k m y Source # pqAndThen :: Monad m => (y -> PQ j k m z) -> (x -> PQ i j m y) -> x -> PQ i k m z Source # | |
Aggregate AggregateArg (Expression (Grouped bys) :: FromType -> FromType -> SchemasType -> [NullType] -> FromType -> NullType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate Methods countStar :: Expression (Grouped bys) lat with db params from (NotNull PGint8) Source # count :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (NotNull PGint8) Source # sum_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGSum ty)) Source # arrayAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGvararray ty)) Source # jsonAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGjson) Source # jsonbAgg :: AggregateArg (ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => AggregateArg (null int ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null int) Source # bitOr :: In int PGIntegral => AggregateArg (null int ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null int) Source # boolAnd :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # boolOr :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # every :: AggregateArg (null PGbool ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGbool) Source # max_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null ty) Source # min_ :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null ty) Source # avg :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # corr :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # covarPop :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # covarSamp :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrAvgX :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrAvgY :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrCount :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGint8) Source # regrIntercept :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrR2 :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSlope :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSxx :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSxy :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # regrSyy :: AggregateArg (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> Expression (Grouped bys) lat with db params from (Null PGfloat8) Source # stddev :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # stddevPop :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # stddevSamp :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # variance :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # varPop :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # varSamp :: AggregateArg (null ty ': []) lat with db params from -> Expression (Grouped bys) lat with db params from (Null (PGAvg ty)) Source # | |
Aggregate (WindowArg grp :: [NullType] -> FromType -> FromType -> SchemasType -> [NullType] -> FromType -> Type) (WindowFunction grp :: FromType -> FromType -> SchemasType -> [NullType] -> FromType -> NullType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Expression.Window Methods countStar :: WindowFunction grp lat with db params from (NotNull PGint8) Source # count :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (NotNull PGint8) Source # sum_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGSum ty)) Source # arrayAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGvararray ty)) Source # jsonAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGjson) Source # jsonbAgg :: WindowArg grp (ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGjsonb) Source # bitAnd :: In int PGIntegral => WindowArg grp (null int ': []) lat with db params from -> WindowFunction grp lat with db params from (Null int) Source # bitOr :: In int PGIntegral => WindowArg grp (null int ': []) lat with db params from -> WindowFunction grp lat with db params from (Null int) Source # boolAnd :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # boolOr :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # every :: WindowArg grp (null PGbool ': []) lat with db params from -> WindowFunction grp lat with db params from (Null PGbool) Source # max_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null ty) Source # min_ :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null ty) Source # avg :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # corr :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # covarPop :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # covarSamp :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrAvgX :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrAvgY :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrCount :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGint8) Source # regrIntercept :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrR2 :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSlope :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSxx :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSxy :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # regrSyy :: WindowArg grp (null PGfloat8 ': (null PGfloat8 ': [])) lat with db params from -> WindowFunction grp lat with db params from (Null PGfloat8) Source # stddev :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # stddevPop :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # stddevSamp :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # variance :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # varPop :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # varSamp :: WindowArg grp (null ty ': []) lat with db params from -> WindowFunction grp lat with db params from (Null (PGAvg ty)) Source # | |
Migratory Definition (Indexed PQ IO ()) Source # | pure migrations |
Defined in Squeal.PostgreSQL.Session.Migration Methods runMigrations :: Path (Migration Definition) db0 db1 -> Indexed PQ IO () db0 db1 Source # | |
Migratory (IsoQ Definition) (IsoQ (Indexed PQ IO ())) Source # | pure rewindable migrations |
Defined in Squeal.PostgreSQL.Session.Migration | |
Migratory (IsoQ (Indexed PQ IO ())) (IsoQ (Indexed PQ IO ())) Source # | impure rewindable migrations |
Migratory (OpQ Definition) (OpQ (Indexed PQ IO ())) Source # | pure rewinds |
Defined in Squeal.PostgreSQL.Session.Migration | |
Migratory (OpQ (Indexed PQ IO ())) (OpQ (Indexed PQ IO ())) Source # | impure rewinds |
Migratory (Indexed PQ IO ()) (Indexed PQ IO ()) Source # | impure migrations |
PostgreSQL provides several index types: B-tree, Hash, GiST, SP-GiST, GIN and BRIN. Each index type uses a different algorithm that is best suited to different types of queries.
Constructors
Btree | B-trees can handle equality and range queries on data that can be sorted into some ordering. |
Hash | Hash indexes can only handle simple equality comparisons. |
Gist | GiST indexes are not a single kind of index, but rather an infrastructure within which many different indexing strategies can be implemented. |
Spgist | SP-GiST indexes, like GiST indexes, offer an infrastructure that supports various kinds of searches. |
Gin | GIN indexes are “inverted indexes” which are appropriate for data values that contain multiple component values, such as arrays. |
Brin | BRIN indexes (a shorthand for Block Range INdexes) store summaries about the values stored in consecutive physical block ranges of a table. |
type FunctionType = ([NullType], ReturnsType) Source #
Use :=>
to pair the parameter types with the return
type of a function.
data ReturnsType Source #
Return type of a function
Constructors
Returns NullType | function |
ReturnsTable RowType | set returning function |
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.
Constraint
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
an Optionality
with a NullType
to produce a ColumnType
or a TableConstraints
and a ColumnsType
to produce a TableType
.
data Optionality Source #
Optionality
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 |
|
NoDef |
|
Instances
NullTyped db (NotNull ty) => ColumnTyped db (NoDef :=> NotNull ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Type Methods columntype :: ColumnTypeExpression db (NoDef :=> NotNull ty) Source # | |
NullTyped db (Null ty) => ColumnTyped db (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Expression.Type Methods columntype :: ColumnTypeExpression db (NoDef :=> Null ty) Source # | |
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> null0 ty0)) (alias1 ::: (def1 :=> null1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema | |
(KnownSymbol col, InlineParam x ty) => InlineColumn (col ::: Optional I (Def :=> x)) (col ::: (Def :=> ty)) Source # | |
(KnownSymbol col, InlineParam x ty) => InlineColumn (col ::: x) (col ::: (NoDef :=> ty)) Source # | |
Defined in Squeal.PostgreSQL.Expression.Inline | |
AddColumn (Def :=> ty) Source # | |
Defined in Squeal.PostgreSQL.Definition.Table | |
AddColumn (NoDef :=> Null ty) Source # | |
Defined in Squeal.PostgreSQL.Definition.Table |
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.
Constructors
Check [Symbol] | |
Unique [Symbol] | |
PrimaryKey [Symbol] | |
ForeignKey [Symbol] Symbol [Symbol] |
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 Label
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.Type.Schema | |
labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # | |
(KnownSymbol label, In label labels) => IsPGlabel label (Expression grp lat with db params from (null (PGenum labels))) Source # | |
Defined in Squeal.PostgreSQL.Expression Methods label :: Expression grp lat with db params from (null (PGenum labels)) Source # |
data PGlabel (label :: Symbol) Source #
Constructors
PGlabel |
Instances
label ~ label1 => IsPGlabel label (PGlabel label1) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema | |
labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # | |
KnownSymbol label => RenderSQL (PGlabel label) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema Methods renderSQL :: PGlabel label -> ByteString Source # | |
All KnownSymbol labels => RenderSQL (NP PGlabel labels) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema |
Data Definition
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 CreateIfNotExists alias x xs where ... Source #
Similar to Create
but no error on pre-existence
Equations
CreateIfNotExists alias x '[] = '[alias ::: x] | |
CreateIfNotExists alias x ((alias ::: y) ': xs) = (alias ::: y) ': xs | |
CreateIfNotExists alias y (x ': xs) = x ': CreateIfNotExists alias y xs |
type family CreateOrReplace alias x xs where ... Source #
Similar to Create
but used to replace values
with the same type.
Equations
CreateOrReplace alias x '[] = '[alias ::: x] | |
CreateOrReplace alias x ((alias ::: x) ': xs) = (alias ::: x) ': xs | |
CreateOrReplace alias x ((alias ::: y) ': xs) = TypeError (((((Text "CreateOrReplace: expected type " :<>: ShowType x) :<>: Text " but alias ") :<>: ShowType alias) :<>: Text " has type ") :<>: ShowType y) | |
CreateOrReplace alias y (x ': xs) = x ': CreateOrReplace 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.
type family DropSchemum alias sch xs where ... Source #
Drop a particular flavor of schemum type
Equations
DropSchemum alias sch '[] = TypeError ((Text "DropSchemum: alias " :<>: ShowType alias) :<>: Text " does not exist") | |
DropSchemum alias sch ((alias ::: sch x) ': xs) = xs | |
DropSchemum alias sch0 ((alias ::: sch1 x) ': xs) = TypeError (((((Text "DropSchemum: expected schemum " :<>: ShowType sch0) :<>: Text " but alias ") :<>: ShowType alias) :<>: Text " has schemum ") :<>: ShowType sch1) | |
DropSchemum alias sch (x ': xs) = x ': DropSchemum alias sch xs |
type family DropIfExists alias xs where ... Source #
Similar to Drop
but no error on non-existence
Equations
DropIfExists alias '[] = '[] | |
DropIfExists alias ((alias ::: x) ': xs) = xs | |
DropIfExists alias (x ': xs) = x ': DropIfExists alias xs |
type family DropSchemumIfExists alias sch xs where ... Source #
Similar to DropSchemum
but no error on non-existence
Equations
DropSchemumIfExists alias sch '[] = '[] | |
DropSchemumIfExists alias sch ((alias ::: sch x) ': xs) = xs | |
DropSchemumIfExists alias sch0 ((alias ::: sch1 x) ': xs) = TypeError (((((Text "DropSchemumIfExists: expected schemum " :<>: ShowType sch1) :<>: Text " but alias ") :<>: ShowType alias) :<>: Text " has schemum ") :<>: ShowType sch0) | |
DropSchemumIfExists alias sch (x ': xs) = x ': DropSchemumIfExists alias sch 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
.
type family AlterIfExists alias x xs where ... Source #
Similar to Alter
but no error on non-existence
Equations
AlterIfExists alias x '[] = '[] | |
AlterIfExists alias x1 ((alias ::: x0) ': xs) = (alias ::: x1) ': xs | |
AlterIfExists alias x1 (x0 ': xs) = x0 ': AlterIfExists 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
.
type family RenameIfExists alias0 alias1 xs where ... Source #
Similar to Rename
but no error on non-existence
Equations
RenameIfExists alias x '[] = '[] | |
RenameIfExists alias0 alias1 ((alias0 ::: x0) ': xs) = (alias1 ::: x0) ': xs | |
RenameIfExists alias0 alias1 (x ': xs) = x ': RenameIfExists alias0 alias1 xs |
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 TableConstraint
s that involve a column
Equations
DropIfConstraintsInvolve column '[] = '[] | |
DropIfConstraintsInvolve column ((alias ::: constraint) ': constraints) = If (ConstraintInvolves column constraint) (DropIfConstraintsInvolve column constraints) ((alias ::: constraint) ': DropIfConstraintsInvolve column constraints) |
Type Classification
type PGNum = '[PGint2, PGint4, PGint8, PGnumeric, PGfloat4, PGfloat8] Source #
Numeric Postgres types.
type family PGTypeOf (ty :: NullType) :: PGType where ... Source #
PGTypeOf
forgets about NULL
and any column constraints.
Equations
PGTypeOf (null 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 :=> null0 ty0)) (alias1 ::: (def1 :=> null1 ty1)) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema |
type family AllNotNull (columns :: ColumnsType) :: Constraint where ... Source #
AllNotNull
is a constraint that proves a ColumnsType
has no NULL
s.
Equations
AllNotNull ((_ ::: (_ :=> NotNull _)) ': columns) = AllNotNull columns | |
AllNotNull '[] = () |
type family NotAllNull (columns :: ColumnsType) :: Constraint where ... Source #
NotAllNull
is a constraint that proves a ColumnsType
has some
NOT NULL
.
Equations
NotAllNull ((_ ::: (_ :=> NotNull _)) ': _) = () | |
NotAllNull ((_ ::: (_ :=> Null _)) ': columns) = NotAllNull columns |
Nullification
type family NullifyType (ty :: NullType) :: NullType where ... Source #
NullifyType
is an idempotent that nullifies a NullType
.
Equations
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
.
Equations
NullifyRow ((column ::: ty) ': columns) = (column ::: NullifyType ty) ': NullifyRow columns | |
NullifyRow '[] = '[] |
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
.
Equations
NullifyFrom ((table ::: columns) ': tables) = (table ::: NullifyRow columns) ': NullifyFrom tables | |
NullifyFrom '[] = '[] |
Table Conversion
type family TableToColumns (table :: TableType) :: ColumnsType where ... Source #
TableToColumns
removes table constraints.
Equations
TableToColumns (constraints :=> columns) = columns |
type family ColumnsToRow (columns :: ColumnsType) :: RowType where ... Source #
ColumnsToRow
removes column constraints.
Equations
ColumnsToRow ((column ::: (_ :=> ty)) ': columns) = (column ::: ty) ': ColumnsToRow columns | |
ColumnsToRow '[] = '[] |
type family TableToRow (table :: TableType) :: RowType where ... Source #
Convert a table to a row type.
Equations
TableToRow tab = ColumnsToRow (TableToColumns tab) |
Updatable
type Updatable table columns = (All (HasIn (TableToColumns table)) columns, AllUnique columns, SListI (TableToColumns table)) Source #
Updatable lists of columns
class AllUnique (xs :: [(Symbol, a)]) Source #
No elem of xs
appears more than once, in the context of assignment.
User Types
type family UserType (db :: SchemasType) (ty :: PGType) where ... Source #
Calculate the schema and name of a user defined type.
Equations
UserType '[] ty = TypeError (Text "No such user type: " :<>: ShowType ty) | |
UserType ((sch ::: schema) ': schemas) ty = UserTypeNamespace sch (UserTypeName schema ty) schemas ty |
type family UserTypeName (schema :: SchemaType) (ty :: PGType) where ... Source #
Calculate the name of a user defined type.
Equations
UserTypeName '[] ty = Nothing | |
UserTypeName ((td ::: Typedef ty) ': _) ty = Just td | |
UserTypeName (_ ': schema) ty = UserTypeName schema ty |
type family UserTypeNamespace (sch :: Symbol) (td :: Maybe Symbol) (schemas :: SchemasType) (ty :: PGType) where ... Source #
Helper to calculate the schema of a user defined type.
Equations
UserTypeNamespace sch Nothing schemas ty = UserType schemas ty | |
UserTypeNamespace sch (Just td) schemas ty = '(sch, td) |