@@ -426,24 +426,19 @@ instance HasTable table schema columns
426426 => IsLabel table (Join params schema '[table ::: columns]) where
427427 fromLabel p = Table $ fromLabel p
428428
429−data From
429+data TableExpression
430430 (params :: [ColumnType])
431431 (schema :: [(Symbol,[(Symbol,ColumnType)])])
432432 (tables :: [(Symbol,[(Symbol,ColumnType)])])
433− = From
433+ = TableExpression
434434 { joinClause :: Join params schema tables
435435 , whereClause :: [Expression params tables ('Required ('NotNull 'PGBool))]
436436 , limitClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
437437 , offsetClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
438438 }
439439
440−join
441− :: Join params schema tables
442− -> From params schema tables
443−join tables = From tables [] [] []
444−
445−renderFrom :: From params schema tables -> ByteString
446−renderFrom (From tables whs' lims' offs') = mconcat
440+renderTableExpression :: TableExpression params schema tables -> ByteString
441+renderTableExpression (TableExpression tables whs' lims' offs') = mconcat
447442 [ renderJoin tables
448443 , renderWheres whs'
449444 , renderLimits lims'
@@ -467,26 +462,31 @@ renderFrom (From tables whs' lims' offs') = mconcat
467462 off:offs -> " OFFSET " <> renderExpression (foldr (+) off offs)
468463
469464instance (HasTable table schema columns, table ~ table')
470− => IsLabel table (From params schema '[table' ::: columns]) where
465+ => IsLabel table (TableExpression params schema '[table' ::: columns]) where
471466 fromLabel p = join (fromLabel p)
472467
468+join
469+ :: Join params schema tables
470+ -> TableExpression params schema tables
471+join tables = TableExpression tables [] [] []
472+
473473where_
474474 :: Expression params tables ('Required ('NotNull 'PGBool))
475− -> From params schema tables
476− -> From params schema tables
477−where_ wh (From tabs whs lims offs) = From tabs (wh:whs) lims offs
475+ -> TableExpression params schema tables
476+ -> TableExpression params schema tables
477+where_ wh (TableExpression tabs whs lims offs) = TableExpression tabs (wh:whs) lims offs
478478
479479limit
480480 :: Expression params '[] ('Required ('NotNull 'PGInt8))
481− -> From params schema tables
482− -> From params schema tables
483−limit lim (From tabs whs lims offs) = From tabs whs (lim:lims) offs
481+ -> TableExpression params schema tables
482+ -> TableExpression params schema tables
483+limit lim (TableExpression tabs whs lims offs) = TableExpression tabs whs (lim:lims) offs
484484
485485offset
486486 :: Expression params '[] ('Required ('NotNull 'PGInt8))
487− -> From params schema tables
488− -> From params schema tables
489−offset off (From tabs whs lims offs) = From tabs whs lims (off:offs)
487+ -> TableExpression params schema tables
488+ -> TableExpression params schema tables
489+offset off (TableExpression tabs whs lims offs) = TableExpression tabs whs lims (off:offs)
490490
491491newtype Selection
492492 (params :: [ColumnType])
@@ -497,25 +497,25 @@ newtype Selection
497497
498498starFrom
499499 :: tables ~ '[table ::: columns]
500− => From params schema tables
500+ => TableExpression params schema tables
501501 -> Selection params schema columns
502−starFrom tabs = UnsafeSelection $ "* FROM " <> renderFrom tabs
502+starFrom tabs = UnsafeSelection $ "* FROM " <> renderTableExpression tabs
503503
504504dotStarFrom
505505 :: HasTable table tables columns
506506 => Alias table
507− -> From params schema tables
507+ -> TableExpression params schema tables
508508 -> Selection params schema columns
509509Alias tab `dotStarFrom` tabs = UnsafeSelection $
510− fromString (symbolVal' tab) <> ".* FROM " <> renderFrom tabs
510+ fromString (symbolVal' tab) <> ".* FROM " <> renderTableExpression tabs
511511
512512from
513513 :: SListI columns
514514 => NP (Aliased (Expression params tables)) columns
515− -> From params schema tables
515+ -> TableExpression params schema tables
516516 -> Selection params schema columns
517517list `from` tabs = UnsafeSelection $
518− renderList list <> " FROM " <> renderFrom tabs
518+ renderList list <> " FROM " <> renderTableExpression tabs
519519 where
520520 renderList
521521 = ByteString.intercalate ", "
@@ -529,7 +529,7 @@ select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
529529
530530subselect
531531 :: Aliased (Selection params schema) table
532− -> From params schema '[table]
532+ -> TableExpression params schema '[table]
533533subselect selection = join (Subselect selection)
534534
535535{-----------------------------------------