Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module embeds Postgres's alias system in Haskell in
a typesafe fashion. Thanks to GHC's OverloadedLabels
extension,
Squeal can reference aliases by prepending with a #
.
Synopsis
- type (:::) (alias :: Symbol) ty = '(alias, ty)
- data Alias (alias :: Symbol) = Alias
- class IsLabel (x :: Symbol) a where
- fromLabel :: a
- data Aliased expression aliased where
- As :: KnownSymbol alias => expression ty -> Alias alias -> Aliased expression (alias ::: ty)
- class KnownSymbol alias => Aliasable alias expression aliased | aliased -> expression, aliased -> alias where
- renderAliased :: (forall ty. expression ty -> ByteString) -> Aliased expression aliased -> ByteString
- mapAliased :: (expr x -> expr y) -> Aliased expr (alias ::: x) -> Aliased expr (alias ::: y)
- class KnownSymbol alias => Has (alias :: Symbol) (fields :: [(Symbol, kind)]) (field :: kind) | alias fields -> field
- type HasUnique alias fields field = fields ~ '[alias ::: field]
- class KnownSymbol alias => HasErr (allFields :: [(Symbol, kind)]) (alias :: Symbol) (fields :: [(Symbol, kind)]) (field :: kind) | alias fields -> field
- class All KnownSymbol aliases => HasAll (aliases :: [Symbol]) (fields :: [(Symbol, kind)]) (subfields :: [(Symbol, kind)]) | aliases fields -> subfields
- class HasIn fields field
- data QualifiedAlias (qualifier :: Symbol) (alias :: Symbol) = QualifiedAlias
- class IsQualified qualifier alias expression where
- data Grouping
- class (KnownSymbol table, KnownSymbol column) => GroupedBy table column bys
- type LookupFailedError needle haystack = LookupFailedError' (LookupFailedError' () (DefaultPrettyPrinter haystack) needle haystack) (PrettyPrintHaystack haystack) needle haystack
- type family PrettyPrintHaystack (haystack :: [(Symbol, k)]) :: PrettyPrintInfo
- data PrettyPrintInfo = PrettyPrintInfo {}
- type family MismatchError (alias :: Symbol) (fields :: [(Symbol, kind)]) (found :: kind) (expected :: kind) :: Constraint where ...
- type family LookupFailedError' (fallbackForUnknownKind :: Constraint) (prettyPrintInfo :: PrettyPrintInfo) (needle :: Symbol) (haystack :: [(Symbol, k)]) :: Constraint where ...
- type family DefaultPrettyPrinter (haystack :: [(Symbol, k)]) :: PrettyPrintInfo where ...
- type family MismatchError' (err :: Constraint) (ppInfo :: PrettyPrintInfo) (alias :: Symbol) (fields :: [(Symbol, kind)]) (found :: kind) (expected :: kind) :: Constraint where ...
Aliases
data Alias (alias :: Symbol) Source #
Alias
es are proxies for a type level string or Symbol
and have an IsLabel
instance so that with -XOverloadedLabels
>>>
:set -XOverloadedLabels
>>>
#foobar :: Alias "foobar"
Alias
Instances
IsQualified qualifier alias (Alias qualifier, Alias alias) Source # | |
alias1 ~ alias2 => IsLabel alias1 (Alias alias2) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(alias0 ~ alias1, alias0 ~ alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) Source # | |
aliases ~ '[alias] => IsLabel alias (NP Alias aliases) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
Eq (Alias alias) Source # | |
Ord (Alias alias) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
Show (Alias alias) Source # | |
Generic (Alias alias) Source # | |
NFData (Alias alias) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
KnownSymbol alias => RenderSQL (Alias alias) Source # |
|
Defined in Squeal.PostgreSQL.Type.Alias renderSQL :: Alias alias -> ByteString Source # | |
All KnownSymbol aliases => RenderSQL (NP Alias aliases) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
type Rep (Alias alias) Source # | |
class IsLabel (x :: Symbol) a where #
Instances
alias1 ~ alias2 => IsLabel alias1 (Alias alias2) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(q' ~ "public", a ~ a') => IsLabel a (QualifiedAlias q' a') Source # | |
Defined in Squeal.PostgreSQL.Type.Alias fromLabel :: QualifiedAlias q' a' # | |
IsLabel fld (MaybeT (DecodeRow row) y) => IsLabel fld (MaybeT (DecodeRow (field ': row)) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
(KnownSymbol fld, FromValue ty (Maybe y)) => IsLabel fld (MaybeT (DecodeRow ((fld ::: ty) ': row)) y) Source # | |
IsLabel fld (DecodeRow row y) => IsLabel fld (DecodeRow (field ': row) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
(KnownSymbol fld, FromValue ty y) => IsLabel fld (DecodeRow ((fld ::: ty) ': row) y) Source # | |
Defined in Squeal.PostgreSQL.Session.Decode | |
(HasUnique rel rels cols, Has col cols ty, by ~ '(rel, col)) => IsLabel col (By rels by) Source # | |
Defined in Squeal.PostgreSQL.Query.Table | |
(q ~ "public", a0 ~ a1, a1 ~ a2, KnownSymbol a2) => IsLabel a0 (Aliased (QualifiedAlias q) (a1 ::: a2)) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias fromLabel :: Aliased (QualifiedAlias q) (a1 ::: a2) # | |
(alias0 ~ alias1, alias0 ~ alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) Source # | |
aliases ~ '[alias] => IsLabel alias (NP Alias aliases) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, columns ~ '[col ::: ty]) => IsLabel col (NP (Aliased (Expression ('Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression ('Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression ('Grouped bys) lat with db params from) column # | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, tys ~ '[ty]) => IsLabel col (NP (Expression ('Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression ('Grouped bys) lat with db params from) tys # | |
(HasUnique tab (Join from lat) row, Has col row ty, columns ~ '[col ::: ty]) => IsLabel col (NP (Aliased (Expression 'Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join from lat) row, Has col row ty, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression 'Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression 'Ungrouped lat with db params from) column # | |
(HasUnique tab (Join from lat) row, Has col row ty, tys ~ '[ty]) => IsLabel col (NP (Expression 'Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression 'Ungrouped lat with db params from) tys # | |
(HasUnique rel rels cols, Has col cols ty, bys ~ '['(rel, col)]) => IsLabel col (NP (By rels) bys) Source # | |
Defined in Squeal.PostgreSQL.Query.Table | |
(ToParam db ty x, ty ~ NullPG x) => IsLabel fld (EncodeParams db '[fld ::: ty] x) Source # | |
Defined in Squeal.PostgreSQL.Session.Encode fromLabel :: EncodeParams db '[fld ::: ty] x # | |
(HasUnique tab (Join from lat) row, Has col row ty) => IsLabel col (AggregateArg '[ty] lat with db params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate fromLabel :: AggregateArg '[ty] lat with db params from # | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys) => IsLabel col (Expression ('Grouped bys) lat with db params from ty) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Expression ('Grouped bys) lat with db params from ty # | |
(HasUnique tab (Join from lat) row, Has col row ty) => IsLabel col (Expression 'Ungrouped lat with db params from ty) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Expression 'Ungrouped lat with db params from ty # | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys) => IsLabel col (WindowArg ('Grouped bys) '[ty] lat with db params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Window | |
(HasUnique tab (Join from lat) row, Has col row ty) => IsLabel col (WindowArg 'Ungrouped '[ty] lat with db params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Window | |
(HasUnique tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty], GroupedBy tab col bys) => IsLabel col (Selection ('Grouped bys) lat with db params from row1) Source # | |
Defined in Squeal.PostgreSQL.Query.Select | |
(HasUnique tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty]) => IsLabel col (Selection 'Ungrouped lat with db params from row1) Source # | |
Defined in Squeal.PostgreSQL.Query.Select |
data Aliased expression aliased where Source #
The As
operator is used to name an expression. As
is like a demoted
version of :::
.
>>>
Just "hello" `As` #hi :: Aliased Maybe ("hi" ::: String)
As (Just "hello") Alias
As :: KnownSymbol alias => expression ty -> Alias alias -> Aliased expression (alias ::: ty) |
Instances
(q0 ~ q1, a0 ~ a1, a1 ~ a2, KnownSymbol a2) => IsQualified q0 a0 (Aliased (QualifiedAlias q1) (a1 ::: a2)) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, columns ~ '[col ::: ty]) => IsQualified tab col (NP (Aliased (Expression ('Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression ('Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, columns ~ '[col ::: ty]) => IsQualified tab col (NP (Aliased (Expression 'Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression 'Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(KnownSymbol alias, tys ~ '[alias ::: ty]) => Aliasable alias (expression ty) (NP (Aliased expression) tys) Source # | |
(KnownSymbol alias, aliased ~ (alias ::: ty)) => Aliasable alias (expression ty) (Aliased expression aliased) Source # | |
(q ~ "public", a0 ~ a1, a1 ~ a2, KnownSymbol a2) => IsLabel a0 (Aliased (QualifiedAlias q) (a1 ::: a2)) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias fromLabel :: Aliased (QualifiedAlias q) (a1 ::: a2) # | |
(alias0 ~ alias1, alias0 ~ alias2, KnownSymbol alias2) => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) Source # | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, columns ~ '[col ::: ty]) => IsLabel col (NP (Aliased (Expression ('Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression ('Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression ('Grouped bys) lat with db params from) column # | |
(HasUnique tab (Join from lat) row, Has col row ty, columns ~ '[col ::: ty]) => IsLabel col (NP (Aliased (Expression 'Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join from lat) row, Has col row ty, column ~ (col ::: ty)) => IsLabel col (Aliased (Expression 'Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: Aliased (Expression 'Ungrouped lat with db params from) column # | |
Eq (expression ty) => Eq (Aliased expression (alias ::: ty)) Source # | |
Ord (expression ty) => Ord (Aliased expression (alias ::: ty)) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias compare :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Ordering # (<) :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Bool # (<=) :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Bool # (>) :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Bool # (>=) :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Bool # max :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) # min :: Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) -> Aliased expression (alias ::: ty) # | |
Show (expression ty) => Show (Aliased expression (alias ::: ty)) Source # | |
class KnownSymbol alias => Aliasable alias expression aliased | aliased -> expression, aliased -> alias where Source #
Instances
(KnownSymbol alias, tys ~ '[alias ::: ty]) => Aliasable alias (expression ty) (NP (Aliased expression) tys) Source # | |
(KnownSymbol alias, aliased ~ (alias ::: ty)) => Aliasable alias (expression ty) (Aliased expression aliased) Source # | |
(KnownSymbol cte, with1 ~ ((cte ::: common) ': with)) => Aliasable cte (statement with db params common) (Path (CommonTableExpression statement db params) with with1) Source # | |
Defined in Squeal.PostgreSQL.Query.With | |
(KnownSymbol cte, with1 ~ ((cte ::: common) ': with)) => Aliasable cte (statement with db params common) (CommonTableExpression statement db params with with1) Source # | |
Defined in Squeal.PostgreSQL.Query.With as :: statement with db params common -> Alias cte -> CommonTableExpression statement db params with with1 Source # | |
(KnownSymbol col, row ~ '[col ::: ty]) => Aliasable col (Expression grp lat with db params from ty) (Selection grp lat with db params from row) Source # | |
Defined in Squeal.PostgreSQL.Query.Select |
renderAliased :: (forall ty. expression ty -> ByteString) -> Aliased expression aliased -> ByteString Source #
>>>
let renderMaybe = fromString . maybe "Nothing" (const "Just")
>>>
renderAliased renderMaybe (Just (3::Int) `As` #an_int)
"Just AS \"an_int\""
mapAliased :: (expr x -> expr y) -> Aliased expr (alias ::: x) -> Aliased expr (alias ::: y) Source #
Map a function over an Aliased
expression.
class KnownSymbol alias => Has (alias :: Symbol) (fields :: [(Symbol, kind)]) (field :: kind) | alias fields -> field Source #
Has alias fields field
is a constraint that proves that
fields
has a field of alias ::: field
, inferring field
from alias
and fields
.
Instances
(KnownSymbol alias, HasErr ('[] :: [(Symbol, kind)]) alias ('[] :: [(Symbol, kind)]) field) => Has alias ('[] :: [(Symbol, kind)]) (field :: kind) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(KnownSymbol alias, HasErr (field' ': fields) alias (field' ': fields) field) => Has alias (field' ': fields :: [(Symbol, kind)]) (field :: kind) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(KnownSymbol alias, HasErr ((alias ::: field0) ': fields) alias ((alias ::: field0) ': fields) field1) => Has alias ((alias ::: field0) ': fields :: [(Symbol, kind)]) (field1 :: kind) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias |
type HasUnique alias fields field = fields ~ '[alias ::: field] Source #
HasUnique alias fields field
is a constraint that proves that
fields
is a singleton of alias ::: field
.
class KnownSymbol alias => HasErr (allFields :: [(Symbol, kind)]) (alias :: Symbol) (fields :: [(Symbol, kind)]) (field :: kind) | alias fields -> field Source #
HasErr
is like Has
except it also retains the original
list of fields being searched, so that error messages are more
useful.
Instances
(KnownSymbol alias, LookupFailedError alias allFields, field ~ (Any :: kind)) => HasErr (allFields :: [(Symbol, kind)]) alias ('[] :: [(Symbol, kind)]) (field :: kind) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(KnownSymbol alias, HasErr allFields alias fields field) => HasErr (allFields :: [(Symbol, kind)]) alias (field' ': fields :: [(Symbol, kind)]) (field :: kind) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(KnownSymbol alias, field0 ~ field1, MismatchError alias allFields field0 field1) => HasErr (allFields :: [(Symbol, k)]) alias ((alias ::: field0) ': fields :: [(Symbol, k)]) (field1 :: k) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias |
class All KnownSymbol aliases => HasAll (aliases :: [Symbol]) (fields :: [(Symbol, kind)]) (subfields :: [(Symbol, kind)]) | aliases fields -> subfields Source #
Instances
HasAll ('[] :: [Symbol]) (fields :: [(Symbol, kind)]) ('[] :: [(Symbol, kind)]) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(Has alias fields field, HasAll aliases fields subfields) => HasAll (alias ': aliases) (fields :: [(Symbol, k)]) ((alias ::: field) ': subfields :: [(Symbol, k)]) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias |
class HasIn fields field Source #
HasIn fields (alias ::: field)
is a constraint that proves that
fields
has a field of alias ::: field
. It is used in UPDATE
s to
choose which subfields to update.
Qualified Aliases
data QualifiedAlias (qualifier :: Symbol) (alias :: Symbol) Source #
QualifiedAlias
es enables multi-schema support by allowing a reference
to a Table
, Typedef
or View
to be qualified by their schemas. By default,
a qualifier of public
is provided.
>>>
:{
let alias1 :: QualifiedAlias "sch" "tab" alias1 = #sch ! #tab alias2 :: QualifiedAlias "public" "vw" alias2 = #vw in printSQL alias1 >> printSQL alias2 :} "sch"."tab" "vw"
Instances
class IsQualified qualifier alias expression where Source #
Analagous to IsLabel
, the constraint
IsQualified
defines !
for a column alias qualified
by a table alias.
Instances
(q ~ q', a ~ a') => IsQualified q a (QualifiedAlias q' a') Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
IsQualified qualifier alias (Alias qualifier, Alias alias) Source # | |
(Has rel rels cols, Has col cols ty, by ~ '(rel, col)) => IsQualified rel col (By rels by) Source # | |
(q0 ~ q1, a0 ~ a1, a1 ~ a2, KnownSymbol a2) => IsQualified q0 a0 (Aliased (QualifiedAlias q1) (a1 ::: a2)) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, columns ~ '[col ::: ty]) => IsQualified tab col (NP (Aliased (Expression ('Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression ('Grouped bys) lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys, tys ~ '[ty]) => IsQualified tab col (NP (Expression ('Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, columns ~ '[col ::: ty]) => IsQualified tab col (NP (Aliased (Expression 'Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, column ~ (col ::: ty)) => IsQualified tab col (Aliased (Expression 'Ungrouped lat with db params from) column) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, tys ~ '[ty]) => IsQualified tab col (NP (Expression 'Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has rel rels cols, Has col cols ty, bys ~ '['(rel, col)]) => IsQualified rel col (NP (By rels) bys) Source # | |
(Has tab (Join from lat) row, Has col row ty) => IsQualified tab col (AggregateArg '[ty] lat with db params from) Source # | |
Defined in Squeal.PostgreSQL.Expression.Aggregate | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys) => IsQualified tab col (Expression ('Grouped bys) lat with db params from ty) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty) => IsQualified tab col (Expression 'Ungrouped lat with db params from ty) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join from lat) row, Has col row ty, GroupedBy tab col bys) => IsQualified tab col (WindowArg ('Grouped bys) '[ty] lat with db params from) Source # | |
(Has tab (Join from lat) row, Has col row ty) => IsQualified tab col (WindowArg 'Ungrouped '[ty] lat with db params from) Source # | |
(Has tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty], GroupedBy tab col bys) => IsQualified tab col (Selection ('Grouped bys) lat with db params from row1) Source # | |
(Has tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty]) => IsQualified tab col (Selection 'Ungrouped lat with db params from row1) Source # | |
Grouping
class (KnownSymbol table, KnownSymbol column) => GroupedBy table column bys Source #
A GroupedBy
constraint indicates that a table qualified column is
a member of the auxiliary namespace created by GROUP BY
clauses and thus,
may be called in an output Expression
without aggregating.
Instances
(KnownSymbol table, KnownSymbol column) => GroupedBy table column ('(table, column) ': bys :: [(Symbol, Symbol)]) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(KnownSymbol table, KnownSymbol column, GroupedBy table column bys) => GroupedBy table column (tabcol ': bys :: [a]) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias |
Error reporting
type LookupFailedError needle haystack = LookupFailedError' (LookupFailedError' () (DefaultPrettyPrinter haystack) needle haystack) (PrettyPrintHaystack haystack) needle haystack Source #
LookupFailedError
reports a nicer error when we fail to look up some needle
in some haystack
type family PrettyPrintHaystack (haystack :: [(Symbol, k)]) :: PrettyPrintInfo Source #
PrettyPrintHaystack
allows us to use the kind of our haystack to come up
with nicer errors. It is implemented as an open type family for dependency reasons
Instances
type PrettyPrintHaystack (haystack :: SchemasType) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: SchemasType) = 'PrettyPrintInfo ('Text "schema (SchemaType)") ('Text "database (SchemasType)") ('Text " " :<>: 'ShowType (Sort (MapFst haystack))) | |
type PrettyPrintHaystack (haystack :: SchemaType) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: SchemaType) = 'PrettyPrintInfo ('Text "table, view, typedef, index, function, or procedure (SchemumType)") ('Text "schema (SchemaType)") (PrettyPrintPartitionedSchema (PartitionSchema haystack)) | |
type PrettyPrintHaystack (haystack :: FromType) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: FromType) = 'PrettyPrintInfo ('Text "row (RowType)") ('Text "from clause (FromType)") ('ShowType (Sort (MapFst haystack))) | |
type PrettyPrintHaystack (haystack :: TableConstraints) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: TableConstraints) = 'PrettyPrintInfo ('Text "constraint (TableConstraint)") ('Text "table (TableConstraints)") ('ShowType (Sort (MapFst haystack))) | |
type PrettyPrintHaystack (haystack :: ColumnsType) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: ColumnsType) = 'PrettyPrintInfo ('Text "column definition (ColumnType)") ('Text "table (ColumnsType)") ('ShowType (Sort (MapFst haystack))) | |
type PrettyPrintHaystack (haystack :: RowType) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema type PrettyPrintHaystack (haystack :: RowType) = 'PrettyPrintInfo ('Text "column (NullType)") ('Text "row (RowType)") ('ShowType (Sort (MapFst haystack))) |
data PrettyPrintInfo Source #
PrettyPrintInfo
is a data type intended to be used at the type level
which describes how to pretty print a haystack in our custom errors. The general intention is we use PrettyPrintHaystack
to define a more specific way of pretty printing our error information for each kind that we care about
type family MismatchError (alias :: Symbol) (fields :: [(Symbol, kind)]) (found :: kind) (expected :: kind) :: Constraint where ... Source #
MismatchError
reports a nicer error with more context when we successfully do a lookup but
find a different field than we expected. As a type family, it ensures that we only do the (expensive)
calculation of coming up with our pretty printing information when we actually have a mismatch
MismatchError _ _ found found = () | |
MismatchError alias fields found expected = MismatchError' (MismatchError' () (DefaultPrettyPrinter fields) alias fields found expected) (PrettyPrintHaystack fields) alias fields found expected |
type family LookupFailedError' (fallbackForUnknownKind :: Constraint) (prettyPrintInfo :: PrettyPrintInfo) (needle :: Symbol) (haystack :: [(Symbol, k)]) :: Constraint where ... Source #
LookupFailedError'
is the workhorse behind LookupFailedError
, but taking an additional type as the first argument. We can put another type error
in there which will only show if LookupFailedError'
is stuck; this allows us to fall back to DefaultPrettyPrinter
when a PrettyPrintHaystack
instance
is missing
LookupFailedError' _ ('PrettyPrintInfo needleName haystackName prettyHaystack) needle rawHaystack = TypeError ((((((((('Text "Could not find " :<>: needleName) :<>: 'Text " named ") :<>: 'ShowType needle) :$$: (('Text "in " :<>: haystackName) :<>: 'Text ":")) :$$: prettyHaystack) :$$: 'Text "") :$$: (('Text "*Raw " :<>: haystackName) :<>: 'Text "*:")) :$$: 'ShowType rawHaystack) :$$: 'Text "") |
type family DefaultPrettyPrinter (haystack :: [(Symbol, k)]) :: PrettyPrintInfo where ... Source #
DefaultPrettyPrinter
provides a default we can use for kinds that don't provide an instance of PrettyPrintInfo
,
although that should generally only be accidental
type family MismatchError' (err :: Constraint) (ppInfo :: PrettyPrintInfo) (alias :: Symbol) (fields :: [(Symbol, kind)]) (found :: kind) (expected :: kind) :: Constraint where ... Source #
MismatchError'
is the workhorse behind MismatchError
, but taking an additional type as the first argument. We can put another type error
in there which will only show if MismatchError'
is stuck; this allows us to fall back to DefaultPrettyPrinter
when a PrettyPrintHaystack
instance
is missing
MismatchError' _ ('PrettyPrintInfo needleName haystackName _) alias fields found expected = TypeError ((((((((('Text "Type mismatch when looking up " :<>: needleName) :<>: 'Text " named ") :<>: 'ShowType alias) :$$: (('Text "in " :<>: haystackName) :<>: 'Text ":")) :$$: 'ShowType fields) :$$: 'Text "") :$$: ('Text "Expected: " :<>: 'ShowType expected)) :$$: ('Text "But found: " :<>: 'ShowType found)) :$$: 'Text "") |