squeal-postgresql-0.5.2.0: Squeal PostgreSQL Library

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

Squeal.PostgreSQL.Schema

Contents

Description

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

Postgres Types

data PGType Source #

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 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
PGSubset PGjsonb Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(@>) :: Operator (null0 PGjsonb) (null1 PGjsonb) (Null PGbool) Source #

(<@) :: Operator (null0 PGjsonb) (null1 PGjsonb) (Null PGbool) Source #

PGSubset PGtsquery Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(@>) :: Operator (null0 PGtsquery) (null1 PGtsquery) (Null PGbool) Source #

(<@) :: Operator (null0 PGtsquery) (null1 PGtsquery) (Null PGbool) Source #

TimeOp PGtimestamp PGinterval Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

TimeOp PGtimestamptz PGinterval Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

TimeOp PGdate PGint4 Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

Methods

(!+) :: Operator (null PGdate) (null PGint4) (null PGdate) Source #

(+!) :: Operator (null PGint4) (null PGdate) (null PGdate) Source #

(!-) :: Operator (null PGdate) (null PGint4) (null PGdate) Source #

(!-!) :: Operator (null PGdate) (null PGdate) (null PGint4) Source #

TimeOp PGtime PGinterval Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

Methods

(!+) :: Operator (null PGtime) (null PGinterval) (null PGtime) Source #

(+!) :: Operator (null PGinterval) (null PGtime) (null PGtime) Source #

(!-) :: Operator (null PGtime) (null PGinterval) (null PGtime) Source #

(!-!) :: Operator (null PGtime) (null PGtime) (null PGinterval) Source #

TimeOp PGtimetz PGinterval Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

Methods

(!+) :: Operator (null PGtimetz) (null PGinterval) (null PGtimetz) Source #

(+!) :: Operator (null PGinterval) (null PGtimetz) (null PGtimetz) Source #

(!-) :: Operator (null PGtimetz) (null PGinterval) (null PGtimetz) Source #

(!-!) :: Operator (null PGtimetz) (null PGtimetz) (null PGinterval) Source #

TimeOp PGinterval PGinterval Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Time

PGSubset (PGvararray ty :: PGType) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(@>) :: Operator (null0 (PGvararray ty)) (null1 (PGvararray ty)) (Null PGbool) Source #

(<@) :: Operator (null0 (PGvararray ty)) (null1 (PGvararray ty)) (Null PGbool) 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 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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> NP (Aliased (Expression outer commons (Grouped bys) schemas params from)) columns Source #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> Aliased (Expression outer commons (Grouped bys) schemas params from) column Source #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> NP (Expression outer commons (Grouped bys) schemas params from) tys Source #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> NP (Aliased (Expression outer commons Ungrouped schemas params from)) columns Source #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> Aliased (Expression outer commons Ungrouped schemas params from) column Source #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

(!) :: Alias tab -> Alias col -> NP (Expression outer commons Ungrouped schemas params from) tys Source #

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Aggregate

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

fromLabel :: NP (Aliased (Expression outer commons (Grouped bys) schemas params from)) columns #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

fromLabel :: NP (Aliased (Expression outer commons Ungrouped schemas params from)) columns #

(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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

fromLabel :: NP (Expression outer commons Ungrouped schemas params from) tys #

(KnownSymbol alias, PGTyped schemas ty) => FieldTyped schemas (alias ::: ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

fieldtype :: Aliased (TypeExpression schemas) (alias ::: ty) Source #

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

Defined in Squeal.PostgreSQL.Expression.Parameter

Methods

parameter :: TypeExpression schemas ty -> Expression outer commons grp schemas (ty' ': params) from ty Source #

HasParameter 1 (ty1 ': tys) ty1 Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Parameter

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Query

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Window

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Json

Additional (Selection outer commons grp schemas params from :: RowType -> Type) Source # 
Instance details

Defined in Squeal.PostgreSQL.Query

Methods

also :: Selection outer commons grp schemas params from ys -> Selection outer commons grp schemas params from xs -> Selection outer commons grp schemas params from (Join xs ys) Source #

NFData (Distinction (Expression outer commons grp schemas params from) ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Aggregate

Methods

rnf :: Distinction (Expression outer commons grp schemas params from) ty -> () #

SListI tys => RenderSQL (Distinction (NP (Expression outer commons grp schemas params from)) tys) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Aggregate

Methods

renderSQL :: Distinction (NP (Expression outer commons grp schemas params from)) tys -> ByteString Source #

RenderSQL (Distinction (Expression outer commons grp schemas params from) ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Aggregate

Methods

renderSQL :: Distinction (Expression outer commons grp schemas params from) ty -> ByteString Source #

(JsonBuildObject tys, In key PGJsonKey) => JsonBuildObject (NotNull key ': (value ': tys)) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression.Json

Methods

jsonBuildObject :: FunctionN (NotNull key ': (value ': tys)) (null PGjson) Source #

jsonbBuildObject :: FunctionN (NotNull key ': (value ': tys)) (null PGjsonb) Source #

HasOid ty => HasAliasedOid (alias ::: nullity ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Binary

ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> nullity0 ty0)) (alias1 ::: (def1 :=> nullity1 ty1)) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

FromValue pg y => FromField (column ::: Null pg) (column ::: Maybe y) Source # 
Instance details

Defined in Squeal.PostgreSQL.Binary

Methods

fromField :: K (Maybe ByteString) (column ::: Null pg) -> (Either Text :.: P) (column ::: Maybe y) Source #

FromValue pg y => FromField (column ::: NotNull pg) (column ::: y) Source # 
Instance details

Defined in Squeal.PostgreSQL.Binary

Methods

fromField :: K (Maybe ByteString) (column ::: NotNull pg) -> (Either Text :.: P) (column ::: y) Source #

ToNullityParam x ty => ToField (alias ::: x) (alias ::: ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Binary

Methods

toField :: P (alias ::: x) -> K (Maybe Encoding) (alias ::: ty) Source #

AddColumn (Def :=> ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

addColumn :: (KnownSymbol column, Has sch schemas schema, Has tab schema (Table table0), table0 ~ (constraints :=> columns)) => Alias column -> ColumnTypeExpression schemas (Def :=> ty) -> AlterTable sch tab schemas (constraints :=> Create column (Def :=> ty) columns) Source #

AddColumn (NoDef :=> Null ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

addColumn :: (KnownSymbol column, Has sch schemas schema, Has tab schema (Table table0), table0 ~ (constraints :=> columns)) => Alias column -> ColumnTypeExpression schemas (NoDef :=> Null ty) -> AlterTable sch tab schemas (constraints :=> Create column (NoDef :=> Null ty) columns) Source #

IsString (Selection outer commons grp schemas params from (("fromOnly" ::: NotNull PGtext) ': ([] :: [(Symbol, NullityType)]))) Source # 
Instance details

Defined in Squeal.PostgreSQL.Query

Methods

fromString :: String -> Selection outer commons grp schemas params from (("fromOnly" ::: NotNull PGtext) ': []) #

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 RowTypes. It can be thought of as a product, or horizontal gluing and is used in FromClauses and TableExpressions.

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 ColumnTypes.

>>> :{
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 # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Migration

Methods

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 # 
Instance details

Defined in Squeal.PostgreSQL.Migration

Methods

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 SchemumTypes.

>>> :{
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.

Equations

Public schema = '["public" ::: schema] 

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
ty0 ~ ty1 => SamePGType (alias0 ::: (def0 :=> nullity0 ty0)) (alias1 ::: (def1 :=> nullity1 ty1)) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

AddColumn (Def :=> ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

addColumn :: (KnownSymbol column, Has sch schemas schema, Has tab schema (Table table0), table0 ~ (constraints :=> columns)) => Alias column -> ColumnTypeExpression schemas (Def :=> ty) -> AlterTable sch tab schemas (constraints :=> Create column (Def :=> ty) columns) Source #

AddColumn (NoDef :=> Null ty) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition

Methods

addColumn :: (KnownSymbol column, Has sch schemas schema, Has tab schema (Table table0), table0 ~ (constraints :=> columns)) => Alias column -> ColumnTypeExpression schemas (NoDef :=> Null ty) -> AlterTable sch tab schemas (constraints :=> Create column (NoDef :=> Null ty) columns) 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.

Instances
SListI (TableToColumns table) => RenderSQL (ConflictClause tab commons schemas params table) Source #

Render a ConflictClause.

Instance details

Defined in Squeal.PostgreSQL.Manipulation

Methods

renderSQL :: ConflictClause tab commons schemas params table -> ByteString Source #

type TableConstraints = [(Symbol, TableConstraint)] Source #

A TableConstraints is a row of TableConstraints.

>>> :{
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.

Equations

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

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"`.

Methods

label :: expr Source #

Instances
label ~ label1 => IsPGlabel label (PGlabel label1) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

label :: PGlabel label1 Source #

labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

label :: NP PGlabel labels Source #

(KnownSymbol label, In label labels) => IsPGlabel label (Expression outer commons grp schemas params from (null (PGenum labels))) Source # 
Instance details

Defined in Squeal.PostgreSQL.Expression

Methods

label :: Expression outer commons grp schemas params from (null (PGenum labels)) Source #

data PGlabel (label :: Symbol) Source #

A PGlabel unit type with an IsPGlabel instance

Constructors

PGlabel 
Instances
label ~ label1 => IsPGlabel label (PGlabel label1) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

label :: PGlabel label1 Source #

labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

label :: NP PGlabel labels Source #

KnownSymbol label => RenderSQL (PGlabel label) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

renderSQL :: PGlabel label -> ByteString Source #

All KnownSymbol labels => RenderSQL (NP PGlabel labels) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Methods

renderSQL :: NP PGlabel labels -> ByteString Source #

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.

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 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) 

class IsNotElem x isElem Source #

Utility class for AllUnique to provide nicer error messages.

Instances
IsNotElem (x :: k) False Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

(TypeError ((Text "Cannot assign to " :<>: ShowType alias) :<>: Text " more than once") :: Constraint) => IsNotElem ((,) alias a :: (k2, k1)) True Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

class AllUnique (xs :: [(Symbol, a)]) Source #

No elem of xs appears more than once, in the context of assignment.

Instances
AllUnique ([] :: [(Symbol, a)]) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

(IsNotElem x (Elem x xs), AllUnique xs) => AllUnique (x ': xs :: [(Symbol, a)]) Source # 
Instance details

Defined in Squeal.PostgreSQL.Schema

Type Classifications

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

Numeric Postgres types.

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

Integral Postgres types.

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

Floating Postgres types.

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

PGTypeOf forgets about NULL and any column constraints.

Equations

PGTypeOf (nullity pg) = pg 

type PGJsonType = '[PGjson, PGjsonb] Source #

Is a type a valid JSON type?

type PGJsonKey = '[PGint2, PGint4, PGtext] Source #

Is a type a valid JSON key?

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 # 
Instance details

Defined in Squeal.PostgreSQL.Schema

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 

Nullifications

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

NullifyType is an idempotent that nullifies a NullityType.

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 '[] = '[] 
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.

Equations

NullifyFrom '[] = '[] 
NullifyFrom ((table ::: columns) ': tables) = (table ::: NullifyRow columns) ': NullifyFrom tables 

Table Conversions

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 '[] = '[] 
ColumnsToRow ((column ::: (constraint :=> ty)) ': columns) = (column ::: ty) ': ColumnsToRow columns 

type family TableToRow (table :: TableType) :: RowType where ... Source #

Convert a table to a row type.

Equations

TableToRow tab = ColumnsToRow (TableToColumns tab)