@@ -10,6 +10,7 @@ Squeal queries.
11{-# LANGUAGE
11{-# LANGUAGE
12 DeriveGeneric
12 DeriveGeneric
14 , GeneralizedNewtypeDeriving
15 , GeneralizedNewtypeDeriving
15 , LambdaCase
16 , LambdaCase
@@ -96,10 +97,10 @@ let
96 '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
97 '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
98 '["col" ::: 'Null 'PGint4]
99 '["col" ::: 'Null 'PGint4]
99− query = selectStar (from (table (#tab `As` #t)))
100+ query = selectStar (from (table #tab))
100in renderQuery query
101in renderQuery query
102−"SELECT * FROM \"tab\" AS \"t\""
103+"SELECT * FROM \"tab\" AS \"tab\""
104restricted query:
105restricted query:
@@ -115,12 +116,12 @@ let
117 ((#col1 + #col2) `As` #sum :* #col1 :* Nil)
118 ((#col1 + #col2) `As` #sum :* #col1 :* Nil)
118− ( from (table (#tab `As` #t))
119+ ( from (table #tab)
119 & where_ (#col1 .> #col2)
120 & where_ (#col1 .> #col2)
120 & where_ (#col2 .> 0) )
121 & where_ (#col2 .> 0) )
121in renderQuery query
122in renderQuery query
123−"SELECT (\"col1\" + \"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"t\" WHERE ((\"col1\" > \"col2\") AND (\"col2\" > 0))"
124+"SELECT (\"col1\" + \"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"tab\" WHERE ((\"col1\" > \"col2\") AND (\"col2\" > 0))"
@@ -132,10 +133,10 @@ let
132 '["col" ::: 'Null 'PGint4]
133 '["col" ::: 'Null 'PGint4]
134 selectStar
135 selectStar
135− (from (subquery (selectStar (from (table (#tab `As` #t))) `As` #sub)))
136+ (from (subquery (selectStar (from (table #tab)) `As` #sub)))
136in renderQuery query
137in renderQuery query
138−"SELECT * FROM (SELECT * FROM \"tab\" AS \"t\") AS \"sub\""
139+"SELECT * FROM (SELECT * FROM \"tab\" AS \"tab\") AS \"sub\""
140limits and offsets:
141limits and offsets:
@@ -146,10 +147,10 @@ let
147 '["col" ::: 'Null 'PGint4]
148 '["col" ::: 'Null 'PGint4]
148 query = selectStar
149 query = selectStar
149− (from (table (#tab `As` #t)) & limit 100 & offset 2 & limit 50 & offset 2)
150+ (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
150in renderQuery query
151in renderQuery query
152−"SELECT * FROM \"tab\" AS \"t\" LIMIT 50 OFFSET 4"
153+"SELECT * FROM \"tab\" AS \"tab\" LIMIT 50 OFFSET 4"
154parameterized query:
155parameterized query:
@@ -160,10 +161,10 @@ let
160 '[ 'NotNull 'PGfloat8]
161 '[ 'NotNull 'PGfloat8]
161 '["col" ::: 'NotNull 'PGfloat8]
162 '["col" ::: 'NotNull 'PGfloat8]
162 query = selectStar
163 query = selectStar
163− (from (table (#tab `As` #t)) & where_ (#col .> param @1))
164+ (from (table #tab) & where_ (#col .> param @1))
164in renderQuery query
165in renderQuery query
166−"SELECT * FROM \"tab\" AS \"t\" WHERE (\"col\" > ($1 :: float8))"
167+"SELECT * FROM \"tab\" AS \"tab\" WHERE (\"col\" > ($1 :: float8))"
168aggregation query:
169aggregation query:
@@ -194,10 +195,10 @@ let
195 '["col" ::: 'Null 'PGint4]
196 '["col" ::: 'Null 'PGint4]
196 query = selectStar
197 query = selectStar
197− (from (table (#tab `As` #t)) & orderBy [#col & AscNullsFirst])
198+ (from (table #tab) & orderBy [#col & AscNullsFirst])
198in renderQuery query
199in renderQuery query
200−"SELECT * FROM \"tab\" AS \"t\" ORDER BY \"col\" ASC NULLS FIRST"
201+"SELECT * FROM \"tab\" AS \"tab\" ORDER BY \"col\" ASC NULLS FIRST"
@@ -266,12 +267,12 @@ let
267 '["col" ::: 'Null 'PGint4]
268 '["col" ::: 'Null 'PGint4]
269− selectStar (from (table (#tab `As` #t)))
270+ selectStar (from (table #tab))
270 `unionAll`
271 `unionAll`
271− selectStar (from (table (#tab `As` #t)))
272+ selectStar (from (table #tab))
272in renderQuery query
273in renderQuery query
274−"(SELECT * FROM \"tab\" AS \"t\") UNION ALL (SELECT * FROM \"tab\" AS \"t\")"
275+"(SELECT * FROM \"tab\" AS \"tab\") UNION ALL (SELECT * FROM \"tab\" AS \"tab\")"
276newtype Query
277newtype Query
277 (schema :: SchemaType)
278 (schema :: SchemaType)
@@ -614,21 +615,25 @@ newtype FromClause schema params relations
615-- | A real `table` is a table from the schema.
616-- | A real `table` is a table from the schema.
617− :: Aliased (Table schema) table
618+ :: Has tab schema ('Table table)
619+ => Aliased Alias (alias ::: tab)
618− -> FromClause schema params '[table]
620+ -> FromClause schema params '[alias ::: TableToRelation table]
619−table = UnsafeFromClause . renderAliasedAs renderTable
621+table (tab `As` alias) = UnsafeFromClause $
622+ renderAlias tab <+> "AS" <+> renderAlias alias
621-- | `subquery` derives a table from a `Query`.
624-- | `subquery` derives a table from a `Query`.
623− :: Aliased (Query schema params) table
626+ :: Aliased (Query schema params) rel
624− -> FromClause schema params '[table]
627+ -> FromClause schema params '[rel]
625subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
628subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
627-- | `view` derives a table from a `View`.
630-- | `view` derives a table from a `View`.
629− :: Aliased (View schema) table
632+ :: Has view schema ('View rel)
633+ => Aliased Alias (alias ::: view)
630− -> FromClause schema params '[table]
634+ -> FromClause schema params '[alias ::: rel]
631−view = UnsafeFromClause . renderAliasedAs renderView
635+view (vw `As` alias) = UnsafeFromClause $
636+ renderAlias vw <+> "AS" <+> renderAlias alias
633{- | @left & crossJoin right@. For every possible combination of rows from
638{- | @left & crossJoin right@. For every possible combination of rows from
634 @left@ and @right@ (i.e., a Cartesian product), the joined table will contain
639 @left@ and @right@ (i.e., a Cartesian product), the joined table will contain