on dev help sign in
names & locations
423d1e9Eitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+26−26
@@ -426,24 +426,19 @@ instance HasTable table schema columns
426 => IsLabel table (Join params schema '[table ::: columns]) where
426 => IsLabel table (Join params schema '[table ::: columns]) where
427 fromLabel p = Table $ fromLabel p
427 fromLabel p = Table $ fromLabel p
428
428
429−data From
429+data TableExpression
430 (params :: [ColumnType])
430 (params :: [ColumnType])
431 (schema :: [(Symbol,[(Symbol,ColumnType)])])
431 (schema :: [(Symbol,[(Symbol,ColumnType)])])
432 (tables :: [(Symbol,[(Symbol,ColumnType)])])
432 (tables :: [(Symbol,[(Symbol,ColumnType)])])
433− = From
433+ = TableExpression
434 { joinClause :: Join params schema tables
434 { joinClause :: Join params schema tables
435 , whereClause :: [Expression params tables ('Required ('NotNull 'PGBool))]
435 , whereClause :: [Expression params tables ('Required ('NotNull 'PGBool))]
436 , limitClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
436 , limitClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
437 , offsetClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
437 , offsetClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
438 }
438 }
439
439
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
440+renderTableExpression :: TableExpression params schema tables -> ByteString
446−renderFrom (From tables whs' lims' offs') = mconcat
441+renderTableExpression (TableExpression tables whs' lims' offs') = mconcat
447 [ renderJoin tables
442 [ renderJoin tables
448 , renderWheres whs'
443 , renderWheres whs'
449 , renderLimits lims'
444 , renderLimits lims'
@@ -467,26 +462,31 @@ renderFrom (From tables whs' lims' offs') = mconcat
467 off:offs -> " OFFSET " <> renderExpression (foldr (+) off offs)
462 off:offs -> " OFFSET " <> renderExpression (foldr (+) off offs)
468
463
469instance (HasTable table schema columns, table ~ table')
464instance (HasTable table schema columns, table ~ table')
470− => IsLabel table (From params schema '[table' ::: columns]) where
465+ => IsLabel table (TableExpression params schema '[table' ::: columns]) where
471 fromLabel p = join (fromLabel p)
466 fromLabel p = join (fromLabel p)
472
467
468+join
469+ :: Join params schema tables
470+ -> TableExpression params schema tables
471+join tables = TableExpression tables [] [] []
472+
473where_
473where_
474 :: Expression params tables ('Required ('NotNull 'PGBool))
474 :: Expression params tables ('Required ('NotNull 'PGBool))
475− -> From params schema tables
475+ -> TableExpression params schema tables
476− -> From params schema tables
476+ -> TableExpression params schema tables
477−where_ wh (From tabs whs lims offs) = From tabs (wh:whs) lims offs
477+where_ wh (TableExpression tabs whs lims offs) = TableExpression tabs (wh:whs) lims offs
478
478
479limit
479limit
480 :: Expression params '[] ('Required ('NotNull 'PGInt8))
480 :: Expression params '[] ('Required ('NotNull 'PGInt8))
481− -> From params schema tables
481+ -> TableExpression params schema tables
482− -> From params schema tables
482+ -> TableExpression params schema tables
483−limit lim (From tabs whs lims offs) = From tabs whs (lim:lims) offs
483+limit lim (TableExpression tabs whs lims offs) = TableExpression tabs whs (lim:lims) offs
484
484
485offset
485offset
486 :: Expression params '[] ('Required ('NotNull 'PGInt8))
486 :: Expression params '[] ('Required ('NotNull 'PGInt8))
487− -> From params schema tables
487+ -> TableExpression params schema tables
488− -> From params schema tables
488+ -> TableExpression params schema tables
489−offset off (From tabs whs lims offs) = From tabs whs lims (off:offs)
489+offset off (TableExpression tabs whs lims offs) = TableExpression tabs whs lims (off:offs)
490
490
491newtype Selection
491newtype Selection
492 (params :: [ColumnType])
492 (params :: [ColumnType])
@@ -497,25 +497,25 @@ newtype Selection
497
497
498starFrom
498starFrom
499 :: tables ~ '[table ::: columns]
499 :: tables ~ '[table ::: columns]
500− => From params schema tables
500+ => TableExpression params schema tables
501 -> Selection params schema columns
501 -> Selection params schema columns
502−starFrom tabs = UnsafeSelection $ "* FROM " <> renderFrom tabs
502+starFrom tabs = UnsafeSelection $ "* FROM " <> renderTableExpression tabs
503
503
504dotStarFrom
504dotStarFrom
505 :: HasTable table tables columns
505 :: HasTable table tables columns
506 => Alias table
506 => Alias table
507− -> From params schema tables
507+ -> TableExpression params schema tables
508 -> Selection params schema columns
508 -> Selection params schema columns
509Alias tab `dotStarFrom` tabs = UnsafeSelection $
509Alias tab `dotStarFrom` tabs = UnsafeSelection $
510− fromString (symbolVal' tab) <> ".* FROM " <> renderFrom tabs
510+ fromString (symbolVal' tab) <> ".* FROM " <> renderTableExpression tabs
511
511
512from
512from
513 :: SListI columns
513 :: SListI columns
514 => NP (Aliased (Expression params tables)) columns
514 => NP (Aliased (Expression params tables)) columns
515− -> From params schema tables
515+ -> TableExpression params schema tables
516 -> Selection params schema columns
516 -> Selection params schema columns
517list `from` tabs = UnsafeSelection $
517list `from` tabs = UnsafeSelection $
518− renderList list <> " FROM " <> renderFrom tabs
518+ renderList list <> " FROM " <> renderTableExpression tabs
519 where
519 where
520 renderList
520 renderList
521 = ByteString.intercalate ", "
521 = ByteString.intercalate ", "
@@ -529,7 +529,7 @@ select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
529
529
530subselect
530subselect
531 :: Aliased (Selection params schema) table
531 :: Aliased (Selection params schema) table
532− -> From params schema '[table]
532+ -> TableExpression params schema '[table]
533subselect selection = join (Subselect selection)
533subselect selection = join (Subselect selection)
534
534
535{-----------------------------------------
535{-----------------------------------------
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+1−1
@@ -109,7 +109,7 @@ spec = do
109 \ CROSS JOIN shippers AS shippers;"
109 \ CROSS JOIN shippers AS shippers;"
110 it "should render INNER JOINs" $ do
110 it "should render INNER JOINs" $ do
111 let
111 let
112− innerJoins :: From '[] JoinTables JoinTables
112+ innerJoins :: TableExpression '[] JoinTables JoinTables
113 innerJoins = join $
113 innerJoins = join $
114 #orders
114 #orders
115 & Inner #customers
115 & Inner #customers