Droplet.Language.Internal.Syntax
- Package
- purescript-droplet
- Repository
- easafe/purescript-droplet
This module defines the entire SQL eDSL, mostly because it'd be a pain to split it
Do not import this module directly, it will break your code and make it not type safe. Use the sanitized Droplet.Language
instead
#Join Source
data Join :: Side -> Row Type -> Type -> Type -> RowList Symbol -> Type -> Type
data Join (k :: Side) (fields :: Row Type) q r (aliases :: SymbolList) rest
Constructors
Join q r rest
Instances
(ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom (Join k fields l r aliases (On c rest)) (Select s unique E) fields
(ToJoin l left las, ToJoin r right ras, Union left right all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Inner fd l r a (On c rest)) fields aliases
(ToJoin l left las, ToJoin r right ras, RowToList right list, ToOuterColumns list out, Union left out all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Outer fd l r a (On c rest)) fields aliases
GroupBySource (Join k columns q r a rest) columns
#On Source
data On c rest
Constructors
On c rest
Instances
(ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom (Join k fields l r aliases (On c rest)) (Select s unique E) fields
(ToJoin l left las, ToJoin r right ras, Union left right all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Inner fd l r a (On c rest)) fields aliases
JOIN ... ON
(ToJoin l left las, ToJoin r right ras, RowToList right list, ToOuterColumns list out, Union left out all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Outer fd l r a (On c rest)) fields aliases
#As Source
newtype As :: Symbol -> Type -> Type
newtype As (alias :: Symbol) rest
Constructors
As rest
Instances
ToSelect (As alias Int)
ToSelect (As alias (Proxy name))
ToSelect (As alias (Path table name))
ToSelect (As alias (Aggregate inp rest fields out))
ToSelect (As alias (PgFunction inp arg fields out))
ToSubExpression (As alias Int)
ToSubExpression (As alias (Proxy name))
ToSubExpression (As alias (Path table name))
ToSubExpression (As alias (PgFunction inp arg fields out))
ToSubExpression (As alias (Aggregate inp r fields out))
(RowToList columns list, QualifiedColumns list alias aliased, Union aliased columns all) => GroupBySource (As alias (Table name columns)) all
(Cons name t e grouped) => ValidGroupByProjection (As alias (Proxy name)) grouped
(Cons name t e grouped) => ValidGroupByProjection (As alias (Aggregate (Proxy name) rest fields out)) grouped
OnlyAggregations (As n (Aggregate i rest f o)) True
(Cons alias Int () projection) => ToProjection (As alias Int) fields aliases projection
(Cons alias t () projection) => ToProjection (As alias (Aggregate inp rest fields t)) fields aliases projection
(Cons alias t () projection) => ToProjection (As alias (PgFunction inp args fields t)) fields aliases projection
(Cons name t e fields, JoinedToMaybe t v, UnwrapDefinition v u, Cons alias u () projection) => ToProjection (As alias (Proxy name)) fields aliases projection
(SymbolListSingleton table single, RowListAppend single aliases all, RowListNub all unique, OuterScopeAlias all unique y, AppendPath table name fullPath, QualifiedColumn y fullPath fields t, Cons alias t () projection) => ToProjection (As alias (Path table name)) fields aliases projection
SourceAlias (As alias (Table name fields)) alias
QueryMustBeAliased (As alias E) alias
QueryOptionallyAliased (As alias E) name alias
(RowToList source list, QualifiedColumns list alias aliased, Union aliased source fields, SymbolListSingleton alias single) => SourceColumns (As alias (Table name source)) fields single
Aliased tables
Resume (As alias E) b (As alias b)
#From Source
data From :: Type -> Row Type -> Type -> Type
data From f (fields :: Row Type) rest
Constructors
From f rest
Instances
ToPrepare (Select s p (From f fields rest))
ToPrepare (Delete (From f fields rest))
(LimitedResults rest) => LimitedResults (From f fields rest)
(SourceAlias f alias, ToCondition c fields alias) => ToWhere c (Select s projection (From f fields E))
(ToCondition c fields Empty) => ToWhere c (Delete (From f fields E))
(GroupBySource f columns) => ToGroupBy (Select s p (From f fd E)) s columns
(GroupBySource f columns) => ToGroupBy (Select s p (From f fd (Where cond E))) s columns
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union aliased projection all) => GroupBySource (Select s projection (From f fd rest)) all
ToAs (Select s p (From f fields rest)) alias
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns E))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (GroupBy g E)))
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd E)))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd (GroupBy g E))))
ToLimit (Select s projection (From fr fields (OrderBy f E)))
ToLimit (Select s projection (From fr fields (OrderBy f (Offset E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
ToOffset (Select s projection (From fr fields (OrderBy f E)))
ToOffset (Select s projection (From fr fields (OrderBy f (Limit n E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(RowToList some slist, RowToList more mlist, CompatibleProjection slist mlist) => ToUnion (Select s some (From f fd rt)) (Select t more (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Union (Select s p (From f fd rt)) sel) (Select t q (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Select s p (From f fd rt)) (Union (Select t q (From g ge es)) sel)
(SourceAlias f table, SymbolListSingleton table single, ToProjection s fields single pro, RowToList pro list, ToSingleColumn list name t, QueryOptionallyAliased rest name alias, Cons alias t () projection) => ToProjection (Select s p (From f fields rest)) fd aliases projection
(QueryOptionallyAliased rest Empty alias) => SourceAlias (Select s p (From f fd rest)) alias
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union projection aliased fields, SymbolListSingleton alias single) => SourceColumns (Select s projection (From f fd rest)) fields single
Aliased subqueries
(Resume rest b c) => Resume (From f fd rest) b (From f fd c)
#Insert Source
newtype Insert rest
Constructors
Insert rest
Instances
ToPrepare (Insert (Into name fields fieldNames (Values v rest)))
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields fn (Values fv E)))
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields DefaultValues E))
(Resume rest b c) => Resume (Insert rest) b (Insert c)
#OrderBy Source
data OrderBy f rest
Constructors
OrderBy f rest
Instances
(LimitedResults rest) => LimitedResults (OrderBy f rest)
(Cons name t e fields, Cons otherName v r fields, UnwrapDefinition v w) => ToArrayAgg (OrderBy (Proxy name) (Proxy otherName)) fields w
(AppendPath alias name fullPath, Cons fullPath t e fields, AppendPath otherAlias otherName otherFullPath, Cons otherFullPath v r fields, UnwrapDefinition v w) => ToArrayAgg (OrderBy (Path alias name) (Path otherAlias otherName)) fields w
(Cons name t e columns, Cons fd g h columns) => ToStringAgg (Proxy name) (OrderBy (Proxy fd) String) columns
(Cons name t e columns) => ToStringAgg (Path table fd) (OrderBy (Proxy name) String) columns
(Cons name t e columns) => ToStringAgg (Proxy name) (OrderBy (Path alias fd) String) columns
ToStringAgg (Path table name) (OrderBy (Path alias fd) String) columns
ToLimit (Select s projection (From fr fields (OrderBy f E)))
ToLimit (Select s projection (From fr fields (OrderBy f (Offset E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
ToOffset (Select s projection (From fr fields (OrderBy f E)))
ToOffset (Select s projection (From fr fields (OrderBy f (Limit n E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(QueryMustBeAliased rest alias) => QueryMustBeAliased (OrderBy f rest) alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (OrderBy f rest) name alias
(Resume rest b c) => Resume (OrderBy f rest) b (OrderBy f c)
#Limit Source
data Limit :: Int -> Type -> Type
data Limit (n :: Int) rest
Constructors
Limit rest
Instances
LimitedResults (Limit 1 rest)
ToOffset (Select s projection (From fr fields (OrderBy f (Limit n E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Limit n rest) alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Limit n rest) name alias
(Resume rest b c) => Resume (Limit n rest) b (Limit n c)
#GroupBy Source
data GroupBy f rest
Constructors
GroupBy f rest
Instances
(LimitedResults rest) => LimitedResults (GroupBy f rest)
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (GroupBy g E)))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd (GroupBy g E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(QueryMustBeAliased rest alias) => QueryMustBeAliased (GroupBy f rest) alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (GroupBy f rest) name alias
(Resume rest b c) => Resume (GroupBy f rest) b (GroupBy f c)
#DefaultValues Source
data DefaultValues
Constructors
Instances
InsertList fields DefaultValues ()
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields DefaultValues E))
#Into Source
data Into :: Symbol -> Row Type -> Type -> Type -> Type
data Into (name :: Symbol) (fields :: Row Type) fieldNames rest
Constructors
Into fieldNames rest
Instances
ToPrepare (Insert (Into name fields fieldNames (Values v rest)))
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields fn (Values fv E)))
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields DefaultValues E))
(Resume rest b c) => Resume (Into n f fd rest) b (Into n f fd c)
#Distinct Source
newtype Distinct s
Constructors
Distinct s
Instances
ToSelect (Distinct s)
(ValidGroupByProjection s grouped) => ValidGroupByProjection (Distinct s) grouped
SortColumnsSource (Distinct s) projection f columns projection
(ToProjection s fields aliases projection) => ToProjection (Distinct s) fields aliases projection
#Where Source
data Where c rest
Constructors
Where c rest
Instances
(LimitedResults rest) => LimitedResults (Where c rest)
(GroupBySource f columns) => ToGroupBy (Select s p (From f fd (Where cond E))) s columns
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd E)))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd (GroupBy g E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Where cd rest) alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Where cd rest) name alias
(Resume rest b c) => Resume (Where cd rest) b (Where cd c)
#Sort Source
data Sort (f :: Type)
Constructors
Instances
(Cons name t e columns) => SortColumns (Sort (Proxy name)) columns
(AppendPath alias name fullPath, Cons fullPath t e columns) => SortColumns (Sort (Path alias name)) columns
#Select Source
data Select :: Type -> Row Type -> Type -> Type
data Select s (projection :: Row Type) rest
SELECT representation. projection
refers to the final output of this statement
Constructors
Select s rest
Instances
ToPrepare (Select s p (From f fields rest))
(ToSubExpression f, LimitedResults rest) => ToSelect (Select f projection rest)
(ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom (Join k fields l r aliases (On c rest)) (Select s unique E) fields
(SourceColumns f fields aliases, ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom f (Select s unique E) fields
(SourceAlias f alias, ToCondition c fields alias) => ToWhere c (Select s projection (From f fields E))
(GroupBySource f columns) => ToGroupBy (Select s p (From f fd E)) s columns
(GroupBySource f columns) => ToGroupBy (Select s p (From f fd (Where cond E))) s columns
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union aliased projection all) => GroupBySource (Select s projection (From f fd rest)) all
ToAs (Select s p (From f fields rest)) alias
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns E))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (GroupBy g E)))
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd E)))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd (GroupBy g E))))
ToLimit (Select s projection (From fr fields (OrderBy f E)))
ToLimit (Select s projection (From fr fields (OrderBy f (Offset E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
ToOffset (Select s projection (From fr fields (OrderBy f E)))
ToOffset (Select s projection (From fr fields (OrderBy f (Limit n E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
(RowToList some slist, RowToList more mlist, CompatibleProjection slist mlist) => ToUnion (Select s some (From f fd rt)) (Select t more (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Union (Select s p (From f fd rt)) sel) (Select t q (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Select s p (From f fd rt)) (Union (Select t q (From g ge es)) sel)
(SourceAlias f table, SymbolListSingleton table single, ToProjection s fields single pro, RowToList pro list, ToSingleColumn list name t, QueryOptionallyAliased rest name alias, Cons alias t () projection) => ToProjection (Select s p (From f fields rest)) fd aliases projection
(QueryOptionallyAliased rest Empty alias) => SourceAlias (Select s p (From f fd rest)) alias
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union projection aliased fields, SymbolListSingleton alias single) => SourceColumns (Select s projection (From f fd rest)) fields single
Aliased subqueries
(Resume rest b c) => Resume (Select s p rest) b (Select s p c)
#Update Source
#Offset Source
data Offset rest
Constructors
Instances
(LimitedResults rest) => LimitedResults (Offset rest)
ToLimit (Select s projection (From fr fields (OrderBy f (Offset E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Offset rest) alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Offset rest) name alias
(Resume rest b c) => Resume (Offset rest) b (Offset c)
#SymbolList Source
type SymbolList = RowList Symbol
A RowList
of Symbol
s
#ToOffset Source
class ToOffset (q :: Type)
Instances
ToOffset (Select s projection (From fr fields (OrderBy f E)))
ToOffset (Select s projection (From fr fields (OrderBy f (Limit n E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToOffset (Select s projection (From fr fields (GroupBy fg (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToOffset (Select s projection (From fr fields (Where cd (OrderBy f (Limit n E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToOffset (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Limit n E))))))
#SingleTypeComposite Source
class SingleTypeComposite (constraints :: Type)
Instances
(SingleTypeComposite t, SingleTypeComposite s) => SingleTypeComposite (Tuple t s)
(Fail (Beside (Beside (Text "Composite ") (QuoteLabel name)) (Text " must not mix constraint types"))) => SingleTypeComposite (Constraint (Composite name) (Tuple t s))
SingleTypeComposite t
#SortColumnsSource Source
class SortColumnsSource :: Type -> Row Type -> Type -> Row Type -> Row Type -> Constraint
class SortColumnsSource (s :: Type) (projection :: Row Type) (f :: Type) (columns :: Row Type) (available :: Row Type) | s -> available
Columns available for sorting this query
N.B: SELECT DISTINCT queries can only be sorted by columns in the projection
Instances
SortColumnsSource (Distinct s) projection f columns projection
(SourceAlias f alias, RowToList columns list, QualifiedColumns list alias qual, Union projection columns pf, Union qual pf all, OnlyAggregations s only, If only projection all available) => SortColumnsSource s projection f columns available
#ValidColumnNames Source
class ValidColumnNames :: RowList Type -> Constraint
class ValidColumnNames (columns :: RowList Type)
Fails on repeated column names
Instances
(ColumnNames columns names, RowListNub names nubbed, UniqueTableColumnNames names nubbed) => ValidColumnNames columns
#IncludeColumn Source
class IncludeColumn :: Symbol -> Type -> RowList Symbol -> RowList Type -> Constraint
class IncludeColumn (name :: Symbol) (t :: Type) (aliases :: SymbolList) (included :: RowList Type) | name -> included
Build a RowList
of the given name and type qualified with each alias
Instances
IncludeColumn name t Nil Nil
(AppendPath alias name fullPath, IncludeColumn name t rest included) => IncludeColumn name t (Cons alias alias rest) (Cons fullPath t included)
#ColumnCannotBeSet Source
class ColumnCannotBeSet (t :: Type)
Fields that cannot be inserted or updated
Instances
(ColumnCannotBeSet constraints) => ColumnCannotBeSet (Column t constraints)
(ColumnCannotBeSet t) => ColumnCannotBeSet (Constraint n t)
(Fail (Text "Identity columns cannot be inserted or updated")) => ColumnCannotBeSet Identity
(ColumnCannotBeSet some, ColumnCannotBeSet more) => ColumnCannotBeSet (Tuple some more)
ColumnCannotBeSet t
#MultipleInsert Source
class MultipleInsert (t :: Type)
Instances
MultipleInsert (Array t)
(MultipleInsert t) => MultipleInsert (Tuple (Array t) u)
(Fail (Text "Multiple INSERT value list must be array")) => MultipleInsert u
#SingleInsert Source
class SingleInsert (t :: Type)
Instances
(SingleInsert t) => SingleInsert (Tuple t u)
(Fail (Text "Single INSERT value list must not be array")) => SingleInsert (Array t)
SingleInsert t
#OnlyAggregations Source
class OnlyAggregations :: Type -> Boolean -> Constraint
class OnlyAggregations (q :: Type) (is :: Boolean) | q -> is
Are all columns aggregated?
Instances
OnlyAggregations (As n (Aggregate i rest f o)) True
(OnlyAggregations a isa, OnlyAggregations b isb, And isa isb is) => OnlyAggregations (Tuple a b) is
OnlyAggregations s False
#ConsistentArity Source
class ConsistentArity (values :: Type)
Makes sure single and multiple insert syntax is not mixed
Instances
ConsistentArity (Array t)
Multiple values, single column
(MultipleInsert u) => ConsistentArity (Tuple (Array t) u)
(SingleInsert u) => ConsistentArity (Tuple t u)
ConsistentArity t
#LimitedResults Source
class LimitedResults (q :: Type)
Subqueries must return a single result
Instances
(LimitedResults rest) => LimitedResults (From f fields rest)
(LimitedResults rest) => LimitedResults (Where c rest)
(LimitedResults rest) => LimitedResults (GroupBy f rest)
(LimitedResults rest) => LimitedResults (OrderBy f rest)
(LimitedResults rest) => LimitedResults (Offset rest)
LimitedResults (Limit 1 rest)
(Fail (Text "Subqueries must return zero or one rows. Are you missing ORDER BY ... LIMIT 1?")) => LimitedResults E
#ColumnNames Source
class ColumnNames :: RowList Type -> RowList Symbol -> Constraint
class ColumnNames (columns :: RowList Type) (names :: SymbolList) | columns -> names
List of all column names in a table
Instances
ColumnNames Nil Nil
(SymbolListSingleton name head, ColumnNames rest tail, RowListAppend head tail all) => ColumnNames (Cons name t rest) all
#UnwrapAll Source
#UniqueColumnNames Source
class UniqueColumnNames :: Row Type -> Row Type -> Constraint
class UniqueColumnNames (some :: Row Type) (more :: Row Type)
Query projections should not repeat column names
Instances
UniqueColumnNames fields fields
#UniqueTableColumnNames Source
class UniqueTableColumnNames :: RowList Symbol -> RowList Symbol -> Constraint
class UniqueTableColumnNames (some :: SymbolList) (more :: SymbolList)
Instances
UniqueTableColumnNames columns columns
#IsRequiredColumn Source
class IsRequiredColumn :: Type -> Boolean -> Constraint
class IsRequiredColumn (t :: Type) (required :: Boolean) | t -> required
Instances
(IsRequiredColumn t tp, IsRequiredColumn constraints cn, And tp cn required) => IsRequiredColumn (Column t constraints) required
(IsRequiredColumn t required) => IsRequiredColumn (Constraint n t) required
IsRequiredColumn (Maybe t) False
(IsRequiredColumn some s, IsRequiredColumn more m, And s m required) => IsRequiredColumn (Tuple some more) required
IsRequiredColumn Default False
IsRequiredColumn Identity False
IsRequiredColumn t True
#TableChecks Source
class TableChecks (t :: Type)
Reused by CREATE and ALTER
Instances
(RowToList columns columnList, ValidColumnNames columnList, ValidConstraints columnList, ConstraintsToRowList columnList list, ValidComposites name list) => TableChecks (Table name columns)
#ColumHasType Source
class ColumHasType (column :: Type)
Constraints must be paired with Column
Instances
ColumHasType (Proxy t)
For ALTER
(ToType t) => ColumHasType t
#IncludeConstraint Source
class IncludeConstraint :: Symbol -> Type -> RowList Type -> Constraint
class IncludeConstraint (name :: Symbol) (constraints :: Type) (list :: RowList Type) | constraints -> list
Constraints that have to be checked across columns
Instances
(IncludeConstraint fn c head, IncludeConstraint fn rest tail, RowListAppend head tail all) => IncludeConstraint fn (Tuple c rest) all
IncludeConstraint columnName (Constraint (Composite name) t) (Cons name (C columnName t) Nil)
IncludeConstraint fn (Constraint name t) (Cons name t Nil)
IncludeConstraint fn PrimaryKey (Cons "0pk" PrimaryKey Nil)
IncludeConstraint fn t Nil
#ToOrderBy Source
class ToOrderBy (f :: Type) (q :: Type)
ORDER BY
Instances
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns E))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (GroupBy g E)))
(SortColumnsSource s projection f columns available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd E)))
(GroupedColumns g columns grouped, Union projection grouped pg, Nub pg available, SortColumns st available) => ToOrderBy st (Select s projection (From f columns (Where cd (GroupBy g E))))
ToOrderBy (Proxy name) String
ToOrderBy (Path alias name) String
ToOrderBy (Proxy name) (Proxy otherName)
ToOrderBy (Path alias name) (Path otherAlias otherName)
#SortColumns Source
class SortColumns :: Type -> Row Type -> Constraint
class SortColumns (f :: Type) (columns :: Row Type) | f -> columns
Instances
(Cons name t e columns) => SortColumns (Proxy name) columns
(AppendPath alias name fullPath, Cons fullPath t e columns) => SortColumns (Path alias name) columns
(Cons name t e columns) => SortColumns (Sort (Proxy name)) columns
(AppendPath alias name fullPath, Cons fullPath t e columns) => SortColumns (Sort (Path alias name)) columns
(Fail (Text "Cannot sort by void function")) => SortColumns (PgFunction input args columns Unit) columns
SortColumns (PgFunction input args columns output) columns
(SortColumns a columns, SortColumns b columns) => SortColumns (Tuple a b) columns
#ConstraintsToRowList Source
class ConstraintsToRowList :: RowList Type -> RowList Type -> Constraint
class ConstraintsToRowList (source :: RowList Type) (constraints :: RowList Type) | source -> constraints
Flatten constraints into a list
Instances
ConstraintsToRowList Nil Nil
(IncludeConstraint name constraints head, ConstraintsToRowList rest tail, RowListAppend head tail all) => ConstraintsToRowList (Cons name (Column t constraints) rest) all
(ConstraintsToRowList rest all) => ConstraintsToRowList (Cons name r rest) all
#CheckComposite Source
class CheckComposite :: Symbol -> Symbol -> Type -> RowList Type -> Constraint
class CheckComposite (tableName :: Symbol) (name :: Symbol) (c :: Type) (rest :: RowList Type)
Instances
CheckComposite tn cn c Nil
(Fail (Beside (Text "Table ") (Beside (QuoteLabel tableName) (Text " has duplicated primary keys. You may want to use a named composite constraint.")))) => CheckComposite tableName cn PrimaryKey (Cons n PrimaryKey rest)
CheckComposite tableName name (C cn t) (Cons name (C cn2 t) rest)
CheckComposite tableName name (C cn (ForeignKey rcn table)) (Cons name (C cn2 (ForeignKey rcn2 table)) rest)
(Fail (Beside (Beside (Text "Constraint ") (QuoteLabel name)) (Beside (Text " declared more than once for table ") (QuoteLabel tableName)))) => CheckComposite tableName name s (Cons name t rest)
(CheckComposite tn name t rest) => CheckComposite tn name t (Cons n s rest)
#ValidComposites Source
class ValidComposites :: Symbol -> RowList Type -> Constraint
class ValidComposites (columnName :: Symbol) (constraints :: RowList Type)
Check constraints across columns
Instances
(CheckComposite tableName name t rest, ValidComposites tableName rest) => ValidComposites tableName (Cons name t rest)
ValidComposites tn Nil
#ValidConstraints Source
class ValidConstraints :: RowList Type -> Constraint
class ValidConstraints (columns :: RowList Type)
Fail on invalid constraints
Instances
ValidConstraints Nil
(UniqueConstraints name constraints, MatchingForeignKey t constraints, SingleTypeComposite constraints, ValidNullableConstraints name t constraints, ValidConstraints rest) => ValidConstraints (Cons name (Column t constraints) rest)
(ColumHasType t, ValidConstraints rest) => ValidConstraints (Cons name t rest)
#ToLimit Source
class ToLimit (q :: Type)
Instances
ToLimit (Select s projection (From fr fields (OrderBy f E)))
ToLimit (Select s projection (From fr fields (OrderBy f (Offset E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f E))))
ToLimit (Select s projection (From fr fields (GroupBy fg (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f E))))
ToLimit (Select s projection (From fr fields (Where cd (OrderBy f (Offset E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f E)))))
ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (OrderBy f (Offset E))))))
#Resume Source
class Resume a b c | a -> b, a b -> c where
Most SQL statement constructors accept a rest
type parameter that refers to next statements
Such parameter is initially filled with E
, meaning that the query ends there
This type class replaces the (nested) final E
for the next statement
Members
resume :: a -> b -> c
Instances
(Resume rest b c) => Resume (Select s p rest) b (Select s p c)
(Resume rest b c) => Resume (From f fd rest) b (From f fd c)
(Resume rest b c) => Resume (Where cd rest) b (Where cd c)
(Resume rest b c) => Resume (GroupBy f rest) b (GroupBy f c)
(Resume rest b c) => Resume (OrderBy f rest) b (OrderBy f c)
(Resume rest b c) => Resume (Limit n rest) b (Limit n c)
(Resume rest b c) => Resume (Offset rest) b (Offset c)
(Resume rest b c) => Resume (Update n f rest) b (Update n f c)
(Resume rest b c) => Resume (Insert rest) b (Insert c)
(Resume rest b c) => Resume (Into n f fd rest) b (Into n f fd c)
(Resume rest b c) => Resume (Values v rest) b (Values v c)
(Resume rest b c) => Resume (Set p rest) b (Set p c)
(Resume rest b c) => Resume (Delete rest) b (Delete c)
Resume (As alias E) b (As alias b)
(Resume rest b c) => Resume (Create rest) b (Create c)
(Resume rest b c) => Resume (Drop rest) b (Drop c)
(Resume rest b c) => Resume (Alter rest) b (Alter c)
Resume E b b
(Resume b a c) => Resume a b c
#UniqueConstraints Source
class UniqueConstraints :: Symbol -> Type -> Constraint
class UniqueConstraints (name :: Symbol) (constraints :: Type)
Constraints must be unique per column
Instances
(IsRepeated name some more, UniqueConstraints name more) => UniqueConstraints name (Tuple some more)
UniqueConstraints name t
#IsRepeated Source
class IsRepeated :: Symbol -> Type -> Type -> Constraint
class IsRepeated (name :: Symbol) (t :: Type) (constraints :: Type)
If a constraint appears more than once in a column
Instances
(IsRepeated name t some, IsRepeated name t more) => IsRepeated name t (Tuple some more)
(Fail (Beside (Beside (Text "Constraint ") (Quote t)) (Beside (Text " declared more than once for column ") (QuoteLabel name)))) => IsRepeated name t t
IsRepeated name t s
#MatchingForeignKey Source
class MatchingForeignKey (t :: Type) (constraints :: Type)
Foreign key name and type must match
Instances
(MatchingForeignKey t some, MatchingForeignKey t more) => MatchingForeignKey t (Tuple some more)
(Cons name s e fields, UnwrapDefinition s t) => MatchingForeignKey t (ForeignKey name (Table n fields))
MatchingForeignKey t s
#ValidNullableConstraints Source
class ValidNullableConstraints :: Symbol -> Type -> Type -> Constraint
class ValidNullableConstraints (name :: Symbol) (t :: Type) (constraints :: Type)
Nullable constraints can only be unique or foreign key
Instances
(IsValidNullableConstraint name constraints) => ValidNullableConstraints name (Maybe t) constraints
ValidNullableConstraints name t constraints
#StarProjection Source
class StarProjection :: RowList Type -> Row Type -> RowList Symbol -> Row Type -> Constraint
class StarProjection (list :: RowList Type) (fields :: Row Type) (aliases :: SymbolList) (projection :: Row Type) | list -> projection
SELECT * FROM should:
- Display column unqualified if it appear both as qualified and unqualified
- Display column qualified if is projected with
Path
Instances
(IncludeAllColumns list aliases included, ListToRow included extended, Union fields extended all, Nub all nubbed, Union extended unqualified nubbed, RowToList unqualified ulist, UnwrapAll ulist projection) => StarProjection list fields aliases projection
#IsValidNullableConstraint Source
class IsValidNullableConstraint :: Symbol -> Type -> Constraint
class IsValidNullableConstraint (name :: Symbol) (constraints :: Type)
Instances
(IsValidNullableConstraint name some, IsValidNullableConstraint name more) => IsValidNullableConstraint name (Tuple some more)
IsValidNullableConstraint name Unique
IsValidNullableConstraint name (ForeignKey n f)
(Fail (Beside (Beside (Beside (Text "Nullable column ") (QuoteLabel name)) (Beside (Text " cannot have ") (Quote t))) (Text " constraint"))) => IsValidNullableConstraint name t
#IsDefault Source
#SymbolListSingleton Source
class SymbolListSingleton :: Symbol -> RowList Symbol -> Constraint
class SymbolListSingleton (alias :: Symbol) (list :: SymbolList) | alias -> list
Creates a SymbolList
single with a single entry
Instances
SymbolListSingleton alias (Cons alias alias Nil)
#SourceAlias Source
class SourceAlias :: Type -> Symbol -> Constraint
class SourceAlias (f :: Type) (alias :: Symbol) | f -> alias
Table/subquery alias or Empty
Instances
SourceAlias (As alias (Table name fields)) alias
(QueryOptionallyAliased rest Empty alias) => SourceAlias (Select s p (From f fd rest)) alias
SourceAlias f Empty
#MissingRequiredColumns Source
class MissingRequiredColumns :: Row Type -> Row Type -> Constraint
class MissingRequiredColumns (required :: Row Type) (inserted :: Row Type)
Slightly clearer type errors for missing columns
Instances
(Union required e inserted) => MissingRequiredColumns required inserted
#QueryMustBeAliased Source
class QueryMustBeAliased :: Type -> Symbol -> Constraint
class QueryMustBeAliased (q :: Type) (alias :: Symbol) | q -> alias
Find this query's alias, or fail at compile time if query is not aliased
Instances
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Where cd rest) alias
(QueryMustBeAliased rest alias) => QueryMustBeAliased (GroupBy f rest) alias
(QueryMustBeAliased rest alias) => QueryMustBeAliased (OrderBy f rest) alias
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Limit n rest) alias
(QueryMustBeAliased rest alias) => QueryMustBeAliased (Offset rest) alias
(Fail (Text "Expected query to end in AS statement")) => QueryMustBeAliased E alias
QueryMustBeAliased (As alias E) alias
#UniqueSources Source
class UniqueSources :: Row Type -> Row Type -> Constraint
class UniqueSources (some :: Row Type) (more :: Row Type)
Joined tables should not be the same
Instances
(Fail (Text "Cannot JOIN source to itself")) => UniqueSources fields fields
UniqueSources some more
#OuterScopeAlias Source
class OuterScopeAlias :: RowList Symbol -> RowList Symbol -> Boolean -> Constraint
class OuterScopeAlias (all :: SymbolList) (unique :: SymbolList) (y :: Boolean) | all unique -> y
Is this column present in the current field source?
Instances
OuterScopeAlias Nil Nil True
OuterScopeAlias (Cons alias alias some) Nil False
OuterScopeAlias Nil (Cons alias alias some) False
(OuterScopeAlias some more y) => OuterScopeAlias (Cons alias alias some) (Cons alias alias more) y
OuterScopeAlias (Cons alias alias some) (Cons otherAlias otherAlias more) False
#OnCondition Source
class OnCondition :: Type -> Row Type -> RowList Symbol -> Constraint
class OnCondition (c :: Type) (fields :: Row Type) (aliases :: SymbolList)
Comparison logic for ON statements
Instances
(OnCondition (Op a b) fields aliases, OnCondition (Op c d) fields aliases) => OnCondition (Op (Op a b) (Op c d)) fields aliases
(OnComparision a fields aliases t, OnComparision b fields aliases u, ValidComparision t u) => OnCondition (Op a b) fields aliases
#QueryOptionallyAliased Source
class QueryOptionallyAliased :: Type -> Symbol -> Symbol -> Constraint
class QueryOptionallyAliased (q :: Type) (name :: Symbol) (alias :: Symbol) | q -> name alias
If this query is in the form of (SELECT ...) AS alias, return alias
, otherwise keep name
Instances
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Where cd rest) name alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (GroupBy f rest) name alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (OrderBy f rest) name alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Limit n rest) name alias
(QueryOptionallyAliased rest name alias) => QueryOptionallyAliased (Offset rest) name alias
QueryOptionallyAliased E name name
QueryOptionallyAliased (As alias E) name alias
#ToJoin Source
class ToJoin :: Type -> Row Type -> RowList Symbol -> Constraint
class ToJoin (q :: Type) (fields :: Row Type) (aliases :: SymbolList) | q -> fields aliases
Given a source q
, compute its joined (non and qualified) fields
Instances
(ToJoin l left las, ToJoin r right ras, Union left right all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Inner fd l r a (On c rest)) fields aliases
JOIN ... ON
(ToJoin l left las, ToJoin r right ras, RowToList right list, ToOuterColumns list out, Union left out all, Nub all fields, RowListAppend las ras aliases) => ToJoin (Join Outer fd l r a (On c rest)) fields aliases
(SourceColumns q fields aliases) => ToJoin q fields aliases
#QualifiedColumn Source
class QualifiedColumn :: Boolean -> Symbol -> Row Type -> Type -> Constraint
class QualifiedColumn (unscoped :: Boolean) (fullPath :: Symbol) (fields :: Row Type) (t :: Type) | unscoped -> fullPath fields t
The type of a qualified column
Instances
QualifiedColumn True fullPath fields OuterScope
(Cons fullPath t d fields, UnwrapDefinition t u, UnwrapNullable u v) => QualifiedColumn False fullPath fields v
#OnComparision Source
class OnComparision :: Type -> Row Type -> RowList Symbol -> Type -> Constraint
class OnComparision (a :: Type) (fields :: Row Type) (aliases :: SymbolList) (t :: Type) | a -> t
Instances
(Cons name t d fields, UnwrapDefinition t u, UnwrapNullable u v) => OnComparision (Proxy name) fields aliases v
(SymbolListSingleton alias single, RowListAppend single aliases all, RowListNub all unique, OuterScopeAlias all unique y, AppendPath alias name fullPath, QualifiedColumn y fullPath fields t) => OnComparision (Path alias name) fields aliases t
OnComparision (Path alias name) fields aliases OuterScope
(ToValue t) => OnComparision t fields aliases t
#ValidGroupByProjection Source
class ValidGroupByProjection :: Type -> Row Type -> Constraint
class ValidGroupByProjection (s :: Type) (grouped :: Row Type) | s -> grouped
Asserts that a SELECT ... GROUP BY projection contains only grouped columns or aggregate functions
Instances
(Cons name t e grouped) => ValidGroupByProjection (Proxy name) grouped
(Cons name t e grouped) => ValidGroupByProjection (As alias (Proxy name)) grouped
(AppendPath table column name, Cons name t e grouped) => ValidGroupByProjection (Path table column) grouped
(Cons name t e grouped) => ValidGroupByProjection (As alias (Aggregate (Proxy name) rest fields out)) grouped
(ValidGroupByProjection a grouped, ValidGroupByProjection b grouped) => ValidGroupByProjection (Tuple a b) grouped
(ValidGroupByProjection s grouped) => ValidGroupByProjection (Distinct s) grouped
#GroupedColumns Source
class GroupedColumns :: Type -> Row Type -> Row Type -> Constraint
class GroupedColumns (f :: Type) (columns :: Row Type) (grouped :: Row Type) | f -> columns grouped
Instances
(Cons name t e columns, Cons name t () grouped) => GroupedColumns (Proxy name) columns grouped
(AppendPath alias name fullPath, Cons fullPath t e columns, Cons fullPath t () g, Cons name t g grouped) => GroupedColumns (Path alias name) columns grouped
(GroupedColumns a columns some, GroupedColumns b columns more, Union some more grouped) => GroupedColumns (Tuple a b) columns grouped
#ToGroupBy Source
#ToOuterColumns Source
class ToOuterColumns :: RowList Type -> Row Type -> Constraint
class ToOuterColumns (list :: RowList Type) (fields :: Row Type) | list -> fields
OUTER JOINs make one side nullable, as a corresponding record may not be found
For ease of use, this class marks the nullable side fields with Joined
, later on ToProjection
will flatten it to Maybe
Instances
ToOuterColumns Nil ()
(Cons name (Joined t) () head, ToOuterColumns rest tail, Union head tail all) => ToOuterColumns (Cons name (Joined t) rest) all
Avoid nesting
Joined
s(Cons name (Joined t) () head, ToOuterColumns rest tail, Union head tail all) => ToOuterColumns (Cons name t rest) all
#ToWhere Source
class ToWhere (c :: Type) (q :: Type)
WHERE can only follow FROM, UPDATE and DELETE
Instances
(SourceAlias f alias, ToCondition c fields alias) => ToWhere c (Select s projection (From f fields E))
(ToCondition c fields Empty) => ToWhere c (Update name fields (Set v E))
(ToCondition c fields Empty) => ToWhere c (Delete (From f fields E))
#JoinedToMaybe Source
class JoinedToMaybe (t :: Type) (v :: Type) | t -> v
Joined
fields appear as Maybe
in projections
Instances
JoinedToMaybe (Joined (f (Maybe t))) (Maybe t)
JoinedToMaybe (Joined (Maybe t)) (Maybe t)
(UnwrapDefinition t u) => JoinedToMaybe (Joined t) (Maybe u)
JoinedToMaybe t t
#CompatibleProjection Source
class CompatibleProjection :: RowList Type -> RowList Type -> Constraint
class CompatibleProjection (pro :: RowList Type) (jection :: RowList Type)
Instances
CompatibleProjection Nil Nil
(CompatibleProjection some more) => CompatibleProjection (Cons name t some) (Cons n t more)
(Fail (Text "UNION column types and count must match")) => CompatibleProjection a b
#ToUnion Source
class ToUnion (q :: Type) (r :: Type)
Instances
(RowToList some slist, RowToList more mlist, CompatibleProjection slist mlist) => ToUnion (Select s some (From f fd rt)) (Select t more (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Union (Select s p (From f fd rt)) sel) (Select t q (From g ge es))
(ToUnion (Select s p (From f fd rt)) (Select t q (From g ge es))) => ToUnion (Select s p (From f fd rt)) (Union (Select t q (From g ge es)) sel)
#RequiredColumns Source
class RequiredColumns :: RowList Type -> Row Type -> Constraint
class RequiredColumns (fieldList :: RowList Type) (required :: Row Type) | fieldList -> required
Compute list of required fields
Instances
RequiredColumns Nil ()
(IsRequiredColumn t is, Cons name t () h, If is h () head, RequiredColumns rest tail, Union head tail required) => RequiredColumns (Cons name t rest) required
#ToAs Source
#ToFrom Source
class ToFrom :: Type -> Type -> Row Type -> Constraint
class ToFrom (f :: Type) (q :: Type) (fields :: Row Type) | q f -> fields
Acceptable sources for FROM statements
Instances
ToFrom (Table name fields) (Delete E) fields
(DELETE) FROM table
(ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom (Join k fields l r aliases (On c rest)) (Select s unique E) fields
(SourceColumns f fields aliases, ToProjection s fields aliases selected, Nub selected unique, UniqueColumnNames selected unique) => ToFrom f (Select s unique E) fields
#GroupBySource Source
class GroupBySource :: Type -> Row Type -> Constraint
class GroupBySource (f :: Type) (columns :: Row Type) | f -> columns
Instances
GroupBySource (Table name columns) columns
(RowToList columns list, QualifiedColumns list alias aliased, Union aliased columns all) => GroupBySource (As alias (Table name columns)) all
GroupBySource (Join k columns q r a rest) columns
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union aliased projection all) => GroupBySource (Select s projection (From f fd rest)) all
#InsertList Source
class InsertList :: Row Type -> Type -> Row Type -> Constraint
class InsertList (fields :: Row Type) (fieldNames :: Type) (inserted :: Row Type) | fieldNames -> fields inserted
Compute list of inserted fields
Instances
InsertList fields DefaultValues ()
(ColumnCannotBeSet t, Cons name t e fields, Cons name t () single) => InsertList fields (Proxy name) single
(InsertList fields f head, InsertList fields rest tail, Union head tail all) => InsertList fields (Tuple f rest) all
#InsertValues Source
class InsertValues :: Row Type -> Type -> Type -> Constraint
class InsertValues (fields :: Row Type) (names :: Type) (t :: Type)
Instances
(InsertValues fields (Proxy name) u) => InsertValues fields (Proxy name) (Array u)
Multiple values, single column
(Cons name t e fields, IsDefault t name) => InsertValues fields (Proxy name) Default
(UnwrapDefinition t u, Cons name t e fields, ToValue u) => InsertValues fields (Proxy name) u
(InsertValues fields name value, InsertValues fields some more) => InsertValues fields (Tuple name some) (Tuple value more)
(InsertValues fields (Tuple name some) (Tuple value more)) => InsertValues fields (Tuple name some) (Array (Tuple value more))
#ToProjection Source
class ToProjection :: Type -> Row Type -> RowList Symbol -> Row Type -> Constraint
class ToProjection (s :: Type) (fields :: Row Type) (aliases :: SymbolList) (projection :: Row Type) | s -> fields projection
Computes SELECT projection as a Row Type
Instances
(Cons name t e fields, JoinedToMaybe t v, UnwrapDefinition v u, Cons name u () projection) => ToProjection (Proxy name) fields aliases projection
Columns
(SymbolListSingleton alias single, RowListAppend single aliases all, RowListNub all unique, OuterScopeAlias all unique y, AppendPath alias name fullPath, QualifiedColumn y fullPath fields t, Cons fullPath t () projection) => ToProjection (Path alias name) fields aliases projection
(Cons alias Int () projection) => ToProjection (As alias Int) fields aliases projection
(Cons alias t () projection) => ToProjection (As alias (Aggregate inp rest fields t)) fields aliases projection
(Cons alias t () projection) => ToProjection (As alias (PgFunction inp args fields t)) fields aliases projection
(Cons name t e fields, JoinedToMaybe t v, UnwrapDefinition v u, Cons alias u () projection) => ToProjection (As alias (Proxy name)) fields aliases projection
(SymbolListSingleton table single, RowListAppend single aliases all, RowListNub all unique, OuterScopeAlias all unique y, AppendPath table name fullPath, QualifiedColumn y fullPath fields t, Cons alias t () projection) => ToProjection (As alias (Path table name)) fields aliases projection
(RowToList fields list, StarProjection list fields aliases projection) => ToProjection Star fields aliases projection
(ToProjection s fields aliases some, ToProjection t fields aliases more, Union some more projection) => ToProjection (Tuple s t) fields aliases projection
(SourceAlias f table, SymbolListSingleton table single, ToProjection s fields single pro, RowToList pro list, ToSingleColumn list name t, QueryOptionallyAliased rest name alias, Cons alias t () projection) => ToProjection (Select s p (From f fields rest)) fd aliases projection
(ToProjection s fields aliases projection) => ToProjection (Distinct s) fields aliases projection
(Fail (Text "Cannot recognize projection")) => ToProjection x f a p
#ToSelect Source
class ToSelect (s :: Type)
Acceptable column types for SELECT statements
Instances
ToSelect (Proxy name)
ToSelect (Path table name)
ToSelect (As alias Int)
ToSelect (As alias (Proxy name))
ToSelect (As alias (Path table name))
ToSelect (As alias (Aggregate inp rest fields out))
ToSelect (As alias (PgFunction inp arg fields out))
(ToSelect r, ToSelect t) => ToSelect (Tuple r t)
ToSelect Star
ToSelect (Distinct s)
(ToSubExpression f, LimitedResults rest) => ToSelect (Select f projection rest)
#ToSingleColumn Source
class ToSingleColumn :: RowList Type -> Symbol -> Type -> Constraint
class ToSingleColumn (fields :: RowList Type) (name :: Symbol) (t :: Type) | fields -> name t
Instances
ToSingleColumn (Cons name (Maybe t) Nil) name (Maybe t)
ToSingleColumn (Cons name t Nil) name (Maybe t)
#ToSubExpression Source
class ToSubExpression (f :: Type)
Only single columns can be projected by subqueries
Instances
ToSubExpression (Proxy name)
ToSubExpression (Path table name)
ToSubExpression (As alias Int)
ToSubExpression (As alias (Proxy name))
ToSubExpression (As alias (Path table name))
ToSubExpression (As alias (PgFunction inp arg fields out))
ToSubExpression (As alias (Aggregate inp r fields out))
(Fail (Text "Subqueries must return a single column")) => ToSubExpression (Tuple a b)
#IncludeAllColumns Source
class IncludeAllColumns :: RowList Type -> RowList Symbol -> RowList Type -> Constraint
class IncludeAllColumns (list :: RowList Type) (aliases :: SymbolList) (all :: RowList Type) | list -> all
Recursively call IncludeColumn
on the given list
Instances
IncludeAllColumns Nil aliases Nil
(IncludeColumn name t aliases included, IncludeAllColumns rest aliases more, RowListAppend included more all) => IncludeAllColumns (Cons name t rest) aliases all
#SourceColumns Source
class SourceColumns :: Type -> Row Type -> RowList Symbol -> Constraint
class SourceColumns (f :: Type) (fields :: Row Type) (aliases :: SymbolList) | f -> fields aliases
Given a source f
, compute its (non and qualified) fields
Instances
SourceColumns (Table name fields) fields Nil
Tables
(RowToList source list, QualifiedColumns list alias aliased, Union aliased source fields, SymbolListSingleton alias single) => SourceColumns (As alias (Table name source)) fields single
Aliased tables
(QueryMustBeAliased rest alias, RowToList projection list, QualifiedColumns list alias aliased, Union projection aliased fields, SymbolListSingleton alias single) => SourceColumns (Select s projection (From f fd rest)) fields single
Aliased subqueries
#ToUpdatePairs Source
class ToUpdatePairs :: Row Type -> Type -> Constraint
class ToUpdatePairs (fields :: Row Type) (pairs :: Type)
Instances
(Cons name t e fields, IsDefault t name) => ToUpdatePairs fields (Op (Proxy name) Default)
(Cons name t e fields, ColumnCannotBeSet t, UnwrapDefinition t u, ToValue u) => ToUpdatePairs fields (Op (Proxy name) u)
(ToUpdatePairs fields head, ToUpdatePairs fields tail) => ToUpdatePairs fields (Tuple head tail)
#ToReturning Source
class ToReturning (f :: Type) (q :: Type) | q -> f
Instances
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields fn (Values fv E)))
(ReturningColumns f fields) => ToReturning f (Insert (Into tn fields DefaultValues E))
#ReturningColumns Source
class ReturningColumns :: Type -> Row Type -> Constraint
class ReturningColumns (f :: Type) (fields :: Row Type) | f -> fields
Instances
(Cons name t e fields) => ReturningColumns (Proxy name) fields
(ReturningColumns a fields, ReturningColumns b fields) => ReturningColumns (Tuple a b) fields
#UniqueAliases Source
class UniqueAliases :: RowList Symbol -> RowList Symbol -> Constraint
class UniqueAliases (some :: SymbolList) (more :: SymbolList)
Joined tables should not repeat table aliases
Instances
UniqueAliases aliases aliases
#QualifiedColumns Source
class QualifiedColumns :: RowList Type -> Symbol -> Row Type -> Constraint
class QualifiedColumns (list :: RowList Type) (alias :: Symbol) (fields :: Row Type) | list alias -> fields
Computes all source fields with their alias
Instances
QualifiedColumns Nil alias ()
(ToPath alias path, Append path name fullPath, Cons fullPath t () head, QualifiedColumns rest alias tail, Union head tail fields) => QualifiedColumns (Cons name t rest) alias fields
#join Source
join :: forall r l aliases unique las ras right rf lf left all source fields. ToJoin l left las => ToJoin r right ras => UniqueSources left right => RowListAppend las ras aliases => RowListNub aliases unique => UniqueAliases aliases unique => Union right left all => Nub all source => Union left lf source => Union right rf source => Union lf rf fields => l -> r -> Join Inner fields l r aliases E
INNER JOIN statement
JOIN sources are the same as FROM
#leftJoin Source
leftJoin :: forall r l las ras list out aliases unique rf lf right left all fields source. ToJoin l left las => ToJoin r right ras => UniqueSources left right => RowListAppend las ras aliases => RowListNub aliases unique => UniqueAliases aliases unique => Union left right all => Nub all source => Union left lf source => Union right rf source => RowToList lf list => ToOuterColumns list out => Union rf out fields => l -> r -> Join Outer fields l r aliases E
LEFT OUTER JOIN statement
JOIN sources are the same as FROM
#groupBy Source
groupBy :: forall f s q sql grouped columns. ToGroupBy q s columns => GroupedColumns f columns grouped => ValidGroupByProjection s grouped => Resume q (GroupBy f E) sql => f -> q -> sql
GROUP BY statement
#from Source
from :: forall f q fields sql. ToFrom f q fields => Resume q (From f fields E) sql => f -> q -> sql
FROM accepts the following sources
- Tables
- Inner and outer joins
- Aliased tables
- Aliased SELECT statements
Due to how SQL binding works, joins and subqueries require brackets to be parsed correctly. For example:
SELECT column FROM (SELECT column FROM table) AS alias
should beselect column # from (select column # from table # as alias)
)SELECT column FROM table alias JOIN other_table other_alias
should beselect column # from ((table # as alias)
join(other_table # as other_alias))
)
To aid composition, SELECT projections are only validated on FROM
#into Source
into :: forall tableName fields fieldNames fieldList required inserted. RowToList fields fieldList => RequiredColumns fieldList required => InsertList fields fieldNames inserted => MissingRequiredColumns required inserted => Table tableName fields -> fieldNames -> Insert E -> Insert (Into tableName fields fieldNames E)
#prepare Source
prepare :: forall q. ToPrepare q => Plan -> q -> Prepare q
https://www.postgresql.org/docs/current/sql-prepare.html
PREPARE statements can be employed to reuse execution plans, and thus optimize performance
Note: droplet always creates server-side parameters for literal values in queries. In the case of PREPARE, however, literals will be parsed as statement parameters
#select Source
select :: forall s projection. ToSelect s => s -> Select s projection E
SELECT can project literals, columns and subqueries with the following considerations:
- Multiple columns are represented by tuples.
Data.Tuple.Nested./\
is convenient for this - Literal values (e.g., numbers) must be aliased (with AS)
- Columns names in projections must be unique, or referenced by different table aliases (e.g., u.name, t.name)
- Subqueries must return a single column
#values Source
values :: forall tableName fields names fieldValues. ConsistentArity fieldValues => InsertValues fields names fieldValues => fieldValues -> Insert (Into tableName fields names E) -> Insert (Into tableName fields names (Values fieldValues E))
- Modules
- Droplet.
Driver - Droplet.
Driver. Internal. Migration - Droplet.
Driver. Internal. Pool - Droplet.
Driver. Internal. Query - Droplet.
Driver. Migration - Droplet.
Driver. Unsafe - Droplet.
Language - Droplet.
Language. Internal. Condition - Droplet.
Language. Internal. Definition - Droplet.
Language. Internal. Function - Droplet.
Language. Internal. Syntax - Droplet.
Language. Internal. Token - Droplet.
Language. Internal. Translate
JOIN ... ON