@@ -12,6 +12,7 @@ Squeal queries.
13 , DeriveDataTypeable
13 , DeriveDataTypeable
14 , DeriveGeneric
14 , DeriveGeneric
15 , FlexibleInstances
16 , FlexibleInstances
17 , GeneralizedNewtypeDeriving
18 , GeneralizedNewtypeDeriving
@@ -45,7 +46,7 @@ module Squeal.PostgreSQL.Query
45 , selectDistinctDotStar
46 , selectDistinctDotStar
46 -- * Table Expressions
47 -- * Table Expressions
47 , TableExpression (..)
48 , TableExpression (..)
48− , renderSubtableExpression
49+ , renderTableExpression
@@ -70,7 +71,7 @@ module Squeal.PostgreSQL.Query
71import Control.DeepSeq
72import Control.DeepSeq
72import Data.ByteString (ByteString)
73import Data.ByteString (ByteString)
73−import Data.Monoid
74+import Data.Monoid hiding (All)
74import Data.String
75import Data.String
75import Data.Word
76import Data.Word
76import Generics.SOP hiding (from)
77import Generics.SOP hiding (from)
@@ -348,7 +349,7 @@ select
348select list tabs = UnsafeQuery $
349select list tabs = UnsafeQuery $
350 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
351 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
351− <+> renderSubtableExpression tabs
352+ <+> renderTableExpression tabs
353-- | After the select list has been processed, the result table can
354-- | After the select list has been processed, the result table can
354-- be subject to the elimination of duplicate rows using `selectDistinct`.
355-- be subject to the elimination of duplicate rows using `selectDistinct`.
@@ -362,7 +363,7 @@ selectDistinct
362selectDistinct list tabs = UnsafeQuery $
363selectDistinct list tabs = UnsafeQuery $
363 "SELECT DISTINCT"
364 "SELECT DISTINCT"
364 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
365 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
365− <+> renderSubtableExpression tabs
366+ <+> renderTableExpression tabs
367-- | The simplest kind of query is `selectStar` which emits all columns
368-- | The simplest kind of query is `selectStar` which emits all columns
368-- that the table expression produces.
369-- that the table expression produces.
@@ -371,7 +372,7 @@ selectStar
371 => TableExpression schema params tables 'Ungrouped
372 => TableExpression schema params tables 'Ungrouped
372 -- ^ intermediate virtual table
373 -- ^ intermediate virtual table
373 -> Query schema params columns
374 -> Query schema params columns
374−selectStar tabs = UnsafeQuery $ "SELECT" <+> "*" <+> renderSubtableExpression tabs
375+selectStar tabs = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression tabs
376-- | A `selectDistinctStar` emits all columns that the table expression
377-- | A `selectDistinctStar` emits all columns that the table expression
377-- produces and eliminates duplicate rows.
378-- produces and eliminates duplicate rows.
@@ -381,32 +382,32 @@ selectDistinctStar
381 -- ^ intermediate virtual table
382 -- ^ intermediate virtual table
382 -> Query schema params columns
383 -> Query schema params columns
383selectDistinctStar tabs = UnsafeQuery $
384selectDistinctStar tabs = UnsafeQuery $
384− "SELECT DISTINCT" <+> "*" <+> renderSubtableExpression tabs
385+ "SELECT DISTINCT" <+> "*" <+> renderTableExpression tabs
386-- | When working with multiple tables, it can also be useful to ask
387-- | When working with multiple tables, it can also be useful to ask
387-- for all the columns of a particular table, using `selectDotStar`.
388-- for all the columns of a particular table, using `selectDotStar`.
388selectDotStar
389selectDotStar
389 :: Has table tables columns
390 :: Has table tables columns
390 => Alias table
391 => Alias table
391− -- ^ particular virtual subtable
392+ -- ^ particular virtual Table
392 -> TableExpression schema params tables 'Ungrouped
393 -> TableExpression schema params tables 'Ungrouped
393 -- ^ intermediate virtual table
394 -- ^ intermediate virtual table
394 -> Query schema params columns
395 -> Query schema params columns
395selectDotStar table tables = UnsafeQuery $
396selectDotStar table tables = UnsafeQuery $
396− "SELECT" <+> renderAlias table <> ".*" <+> renderSubtableExpression tables
397+ "SELECT" <+> renderAlias table <> ".*" <+> renderTableExpression tables
398-- | A `selectDistinctDotStar` asks for all the columns of a particular table,
399-- | A `selectDistinctDotStar` asks for all the columns of a particular table,
399-- and eliminates duplicate rows.
400-- and eliminates duplicate rows.
400selectDistinctDotStar
401selectDistinctDotStar
401 :: Has table tables columns
402 :: Has table tables columns
402 => Alias table
403 => Alias table
403− -- ^ particular virtual subtable
404+ -- ^ particular virtual Table
404 -> TableExpression schema params tables 'Ungrouped
405 -> TableExpression schema params tables 'Ungrouped
405 -- ^ intermediate virtual table
406 -- ^ intermediate virtual table
406 -> Query schema params columns
407 -> Query schema params columns
407selectDistinctDotStar table tables = UnsafeQuery $
408selectDistinctDotStar table tables = UnsafeQuery $
408 "SELECT DISTINCT" <+> renderAlias table <> ".*"
409 "SELECT DISTINCT" <+> renderAlias table <> ".*"
409− <+> renderSubtableExpression tables
410+ <+> renderTableExpression tables
411{-----------------------------------------
412{-----------------------------------------
412Table Expressions
413Table Expressions
@@ -466,10 +467,10 @@ data TableExpression
468-- | Render a `TableExpression`
469-- | Render a `TableExpression`
469−renderSubtableExpression
470+renderTableExpression
470 :: TableExpression schema params tables grouping
471 :: TableExpression schema params tables grouping
471 -> ByteString
472 -> ByteString
472−renderSubtableExpression
473+renderTableExpression
473 (TableExpression tables whs' grps' hvs' srts' lims' offs') = mconcat
474 (TableExpression tables whs' grps' hvs' srts' lims' offs') = mconcat
474 [ "FROM ", renderFromClause tables
475 [ "FROM ", renderFromClause tables
475 , renderWheres whs'
476 , renderWheres whs'
@@ -612,7 +613,7 @@ their placement in SQL.
613data FromClause schema params tables where
614data FromClause schema params tables where
615− :: Aliased (Subtable (TablesToRelations schema)) table
616+ :: Aliased (Table schema) table
616 -> FromClause schema params '[table]
617 -> FromClause schema params '[table]
618 :: Aliased (Query schema params) table
619 :: Aliased (Query schema params) table
@@ -646,7 +647,7 @@ data FromClause schema params tables where
646-- | Renders a `FromClause`.
647-- | Renders a `FromClause`.
647renderFromClause :: FromClause schema params tables -> ByteString
648renderFromClause :: FromClause schema params tables -> ByteString
648renderFromClause = \case
649renderFromClause = \case
649− Table table -> renderAliasedAs renderSubtable table
650+ Table table -> renderAliasedAs renderTable table
650 Subquery selection -> renderAliasedAs (parenthesized . renderQuery) selection
651 Subquery selection -> renderAliasedAs (parenthesized . renderQuery) selection
651 CrossJoin right left ->
652 CrossJoin right left ->
652 renderFromClause left <+> "CROSS JOIN" <+> renderFromClause right
653 renderFromClause left <+> "CROSS JOIN" <+> renderFromClause right