@@ -17,17 +17,19 @@
1717
1818module Squeel.PostgreSQL.Statement where
1919
20+import Control.Category
2021import Data.ByteString (ByteString)
2122import Data.Foldable
2223import Data.Maybe
2324import Data.Monoid
2425import Data.Ratio
2526import Data.String
27+import Data.Word
2628import Generics.SOP
2729import GHC.Exts
2830import GHC.OverloadedLabels
2931import GHC.TypeLits
30−import Prelude hiding (RealFrac(..))
32+import Prelude hiding (RealFrac(..), id, (.))
3133
3234import qualified Data.ByteString as ByteString
3335
@@ -267,33 +269,34 @@ instance IsString (Expression params tables ('Required (nullity 'PGText))) where
267269 '\\' -> "\\\\"
268270 c -> [c]
269271
270−type Predicate params tables = Expression params tables ('Required ('NotNull 'PGBool))
272+type Condition params tables =
273+ Expression params tables ('Required ('NotNull 'PGBool))
271274
272−true :: Predicate params tables
275+true :: Condition params tables
273276true = UnsafeExpression "TRUE"
274277
275−false :: Predicate params tables
278+false :: Condition params tables
276279false = UnsafeExpression "FALSE"
277280
278281notB
279− :: Predicate params tables
280− -> Predicate params tables
282+ :: Condition params tables
283+ -> Condition params tables
281284notB = unsafeUnaryOp "NOT"
282285
283286(&&*)
284− :: Predicate params tables
285− -> Predicate params tables
286− -> Predicate params tables
287+ :: Condition params tables
288+ -> Condition params tables
289+ -> Condition params tables
287290(&&*) = unsafeBinaryOp "AND"
288291
289292(||*)
290− :: Predicate params tables
291− -> Predicate params tables
292− -> Predicate params tables
293+ :: Condition params tables
294+ -> Condition params tables
295+ -> Condition params tables
293296(||*) = unsafeBinaryOp "OR"
294297
295298caseWhenThenElse
296− :: [(Predicate params tables, Expression params tables ty)]
299+ :: [(Condition params tables, Expression params tables ty)]
297300 -> Expression params tables ty
298301 -> Expression params tables ty
299302caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
@@ -310,7 +313,7 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
310313 ]
311314
312315ifThenElse
313− :: Predicate params tables
316+ :: Condition params tables
314317 -> Expression params tables ty
315318 -> Expression params tables ty
316319 -> Expression params tables ty
@@ -319,37 +322,37 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
319322(==*)
320323 :: Expression params tables ty
321324 -> Expression params tables ty
322− -> Predicate params tables
325+ -> Condition params tables
323326(==*) = unsafeBinaryOp "="
324327
325328(/=*)
326329 :: Expression params tables ty
327330 -> Expression params tables ty
328− -> Predicate params tables
331+ -> Condition params tables
329332(/=*) = unsafeBinaryOp "<>"
330333
331334(>=*)
332335 :: Expression params tables ty
333336 -> Expression params tables ty
334− -> Predicate params tables
337+ -> Condition params tables
335338(>=*) = unsafeBinaryOp ">="
336339
337340(<*)
338341 :: Expression params tables ty
339342 -> Expression params tables ty
340− -> Predicate params tables
343+ -> Condition params tables
341344(<*) = unsafeBinaryOp "<"
342345
343346(<=*)
344347 :: Expression params tables ty
345348 -> Expression params tables ty
346− -> Predicate params tables
349+ -> Condition params tables
347350(<=*) = unsafeBinaryOp "<="
348351
349352(>*)
350353 :: Expression params tables ty
351354 -> Expression params tables ty
352− -> Predicate params tables
355+ -> Condition params tables
353356(>*) = unsafeBinaryOp ">"
354357
355358{-----------------------------------------
@@ -357,7 +360,6 @@ tables
357360-----------------------------------------}
358361
359362newtype Table
360− (params :: [ColumnType])
361363 (schema :: [(Symbol,[(Symbol,ColumnType)])])
362364 (columns :: [(Symbol,ColumnType)])
363365 = UnsafeTable { renderTable :: ByteString }
@@ -365,7 +367,7 @@ newtype Table
365367
366368class KnownSymbol table => HasTable table tables columns
367369 | table tables -> columns where
368− getTable :: Proxy# table -> Table params tables columns
370+ getTable :: Proxy# table -> Table tables columns
369371 getTable table = UnsafeTable $ fromString $ symbolVal' table
370372instance {-# OVERLAPPING #-} KnownSymbol table
371373 => HasTable table ((table ::: columns) ': tables) columns
@@ -374,9 +376,136 @@ instance {-# OVERLAPPABLE #-}
374376 => HasTable table (table' ': schema) columns
375377
376378instance HasTable table schema columns
377− => IsLabel table (Table params schema columns) where
379+ => IsLabel table (Table schema columns) where
378380 fromLabel = getTable
379381
382+data TableReference params schema tables where
383+ Table
384+ :: Aliased (Table schema) table
385+ -> TableReference params schema '[table]
386+ Subquery
387+ :: Aliased (Query schema params) table
388+ -> TableReference params schema '[table]
389+ CrossJoin
390+ :: TableReference params schema right
391+ -> TableReference params schema left
392+ -> TableReference params schema (Join left right)
393+ InnerJoin
394+ :: TableReference params schema right
395+ -> Condition params (Join left right)
396+ -> TableReference params schema left
397+ -> TableReference params schema (Join left right)
398+ LeftOuterJoin
399+ :: TableReference params schema right
400+ -> Condition params (Join left right)
401+ -> TableReference params schema left
402+ -> TableReference params schema (Join left (NullifyTables right))
403+ RightOuterJoin
404+ :: TableReference params schema right
405+ -> Condition params (Join left right)
406+ -> TableReference params schema left
407+ -> TableReference params schema (Join (NullifyTables left) right)
408+ FullOuterJoin
409+ :: TableReference params schema right
410+ -> Condition params (Join left right)
411+ -> TableReference params schema left
412+ -> TableReference params schema
413+ (Join (NullifyTables left) (NullifyTables right))
414+
415+renderTableReference :: TableReference params schema tables -> ByteString
416+renderTableReference = \case
417+ Table table -> renderAliased renderTable table
418+ Subquery selection -> renderAliased renderQuery selection
419+ CrossJoin right left -> mconcat
420+ [ renderTableReference left
421+ , " CROSS JOIN "
422+ , renderTableReference right
423+ ]
424+ InnerJoin right on left -> mconcat
425+ [ renderTableReference left
426+ , " INNER JOIN "
427+ , renderTableReference right
428+ , " ON "
429+ , renderExpression on
430+ ]
431+ LeftOuterJoin right on left -> mconcat
432+ [ renderTableReference left
433+ , " LEFT OUTER JOIN "
434+ , renderTableReference right
435+ , " ON "
436+ , renderExpression on
437+ ]
438+ RightOuterJoin right on left -> mconcat
439+ [ renderTableReference left
440+ , " RIGHT OUTER JOIN "
441+ , renderTableReference right
442+ , " ON "
443+ , renderExpression on
444+ ]
445+ FullOuterJoin right on left -> mconcat
446+ [ renderTableReference left
447+ , " FULL OUTER JOIN "
448+ , renderTableReference right
449+ , " ON "
450+ , renderExpression on
451+ ]
452+
453+data TableExpression
454+ (params :: [ColumnType])
455+ (schema :: [(Symbol,[(Symbol,ColumnType)])])
456+ (tables :: [(Symbol,[(Symbol,ColumnType)])])
457+ = TableExpression
458+ { fromClause :: TableReference params schema tables
459+ , whereClause :: [Condition params tables]
460+ , limitClause :: Maybe Word64
461+ , offsetClause :: Maybe Word64
462+ }
463+
464+renderTableExpression
465+ :: TableExpression params schema tables
466+ -> ByteString
467+renderTableExpression (TableExpression tables whs' lims' offs') = mconcat
468+ [ "FROM ", renderTableReference tables
469+ , renderWheres whs'
470+ , renderLimits lims'
471+ , renderOffsets offs'
472+ ] where
473+ renderWheres = \case
474+ [] -> ""
475+ wh:[] -> " WHERE " <> renderExpression wh
476+ wh:whs -> " WHERE " <> renderExpression (foldr (&&*) wh whs)
477+ renderLimits = \case
478+ Nothing -> ""
479+ Just lim -> " LIMIT " <> fromString (show lim)
480+ renderOffsets = \case
481+ Nothing -> ""
482+ Just off -> " OFFSET " <> fromString (show off)
483+
484+from
485+ :: TableReference params schema tables
486+ -> TableExpression params schema tables
487+from tables = TableExpression tables [] Nothing Nothing
488+
489+where_
490+ :: Condition params tables
491+ -> TableExpression params schema tables
492+ -> TableExpression params schema tables
493+where_ wh tables = tables {whereClause = wh : whereClause tables}
494+
495+limit
496+ :: Word64
497+ -> TableExpression params schema tables
498+ -> TableExpression params schema tables
499+limit lim tables = tables
500+ {limitClause = maybe (Just lim) (Just . min lim) (limitClause tables)}
501+
502+offset
503+ :: Word64
504+ -> TableExpression params schema tables
505+ -> TableExpression params schema tables
506+offset off tables = tables
507+ {offsetClause = maybe (Just off) (Just . (off +)) (offsetClause tables)}
508+
380509{-----------------------------------------
381510type expressions
382511-----------------------------------------}
@@ -511,209 +640,80 @@ instance PGTyped 'PGJsonb where pgtype = jsonb
511640statements
512641-----------------------------------------}
513642
514−newtype Statement
515− (params :: [ColumnType])
516− (columns :: [(Symbol,ColumnType)])
643+newtype DataDefinition
517644 (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
518645 (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
519− = UnsafeStatement { renderStatement :: ByteString }
520− deriving (Show,Eq)
646+ = UnsafeDataDefinition { renderDataDefinition :: ByteString }
521647
522−-- newtype PreparedStatement
523−-- (params :: [ColumnType])
524−-- (columns :: [(Symbol,ColumnType)])
525−-- (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
526−-- (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
527−-- = UnsafePreparedStatement { renderPreparedStatement :: ByteString }
528−-- deriving (Show,Eq)
529−
530−{-----------------------------------------
531−SELECT statements
532−-----------------------------------------}
648+instance Category DataDefinition where
649+ id = UnsafeDataDefinition ";"
650+ dd1 . dd0 = UnsafeDataDefinition $
651+ renderDataDefinition dd0 <> " " <> renderDataDefinition dd1
533652
534−data Join params schema tables where
535− Table
536− :: Aliased (Table params schema) table
537− -> Join params schema '[table]
538− Subselect
539− :: Aliased (Selection params schema) table
540− -> Join params schema '[table]
541− Cross
542− :: Aliased (Table params schema) table
543− -> Join params schema tables
544− -> Join params schema (table ': tables)
545− Inner
546− :: Aliased (Table params schema) table
547− -> Predicate params (table ': tables)
548− -> Join params schema tables
549− -> Join params schema (table ': tables)
550− LeftOuter
551− :: Aliased (Table params schema) right
552− -> Predicate params '[left,right]
553− -> Join params schema (tables)
554− -> Join params schema (NullifyTable right ': left ': tables)
555− RightOuter
556− :: Aliased (Table params schema) right
557− -> Predicate params '[left,right]
558− -> Join params schema (left : tables)
559− -> Join params schema (right ': NullifyTable left ': tables)
560− FullOuter
561− :: Aliased (Table params schema) right
562− -> Predicate params '[left,right]
563− -> Join params schema (left : tables)
564− -> Join params schema
565− (NullifyTable right ': NullifyTable left ': tables)
566−
567−renderJoin :: Join params schema tables -> ByteString
568−renderJoin = \case
569− Table table -> renderAliased renderTable table
570− Subselect selection -> "SELECT " <> renderAliased renderSelection selection
571− Cross table tables -> mconcat
572− [ renderJoin tables
573− , " CROSS JOIN "
574− , renderAliased renderTable table
575− ]
576− Inner table on tables -> mconcat
577− [ renderJoin tables
578− , " INNER JOIN "
579− , renderAliased renderTable table
580− , " ON "
581− , renderExpression on
582− ]
583− LeftOuter table on tables -> mconcat
584− [ renderJoin tables
585− , " LEFT OUTER JOIN "
586− , renderAliased renderTable table
587− , " ON "
588− , renderExpression on
589− ]
590− RightOuter table on tables -> mconcat
591− [ renderJoin tables
592− , " RIGHT OUTER JOIN "
593− , renderAliased renderTable table
594− , " ON "
595− , renderExpression on
596− ]
597− FullOuter table on tables -> mconcat
598− [ renderJoin tables
599− , " FULL OUTER JOIN "
600− , renderAliased renderTable table
601− , " ON "
602− , renderExpression on
603− ]
604−
605−instance HasTable table schema columns
606− => IsLabel table (Join params schema '[table ::: columns]) where
607− fromLabel p = Table $ fromLabel p
608−
609−data TableExpression
610− (params :: [ColumnType])
653+newtype DataManipulation
611654 (schema :: [(Symbol,[(Symbol,ColumnType)])])
612− (tables :: [(Symbol,[(Symbol,ColumnType)])])
613− = TableExpression
614− { joinClause :: Join params schema tables
615− , whereClause :: [Predicate params tables]
616− , limitClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
617− , offsetClause :: [Expression params '[] ('Required ('NotNull 'PGInt8))]
618− }
619−
620−renderTableExpression :: TableExpression params schema tables -> ByteString
621−renderTableExpression (TableExpression tables whs' lims' offs') = mconcat
622− [ renderJoin tables
623− , renderWheres whs'
624− , renderLimits lims'
625− , renderOffsets offs'
626− ] where
627− renderWheres = \case
628− [] -> ""
629− wh:[] -> " WHERE " <> renderExpression wh
630− wh:whs -> " WHERE " <> renderExpression (foldr (&&*) wh whs)
631− renderLimits = \case
632− [] -> ""
633− lim:[] -> " LIMIT " <> renderExpression lim
634− lims -> mconcat
635− [ " LIMIT LEAST("
636− , ByteString.intercalate ", " (renderExpression <$> reverse lims)
637− , ")"
638− ]
639− renderOffsets = \case
640− [] -> ""
641− off:[] -> " OFFSET " <> renderExpression off
642− off:offs -> " OFFSET " <> renderExpression (foldr (+) off offs)
643−
644−instance (HasTable table schema columns, table ~ table')
645− => IsLabel table (TableExpression params schema '[table' ::: columns]) where
646− fromLabel p = join (fromLabel p)
647−
648−join
649− :: Join params schema tables
650− -> TableExpression params schema tables
651−join tables = TableExpression tables [] [] []
652−
653−where_
654− :: Predicate params tables
655− -> TableExpression params schema tables
656− -> TableExpression params schema tables
657−where_ wh (TableExpression tabs whs lims offs) =
658− TableExpression tabs (wh:whs) lims offs
659−
660−limit
661− :: Expression params '[] ('Required ('NotNull 'PGInt8))
662− -> TableExpression params schema tables
663− -> TableExpression params schema tables
664−limit lim (TableExpression tabs whs lims offs) =
665− TableExpression tabs whs (lim:lims) offs
666−
667−offset
668− :: Expression params '[] ('Required ('NotNull 'PGInt8))
669− -> TableExpression params schema tables
670− -> TableExpression params schema tables
671−offset off (TableExpression tabs whs lims offs) =
672− TableExpression tabs whs lims (off:offs)
673−
674−newtype Selection
675655 (params :: [ColumnType])
676− (schema :: [(Symbol,[(Symbol,ColumnType)])])
677656 (columns :: [(Symbol,ColumnType)])
678− = UnsafeSelection { renderSelection :: ByteString }
679− deriving (Show,Eq)
657+ = UnsafeDataManipulation { renderDataManipulation :: ByteString }
680658
681−starFrom
682− :: tables ~ '[table ::: columns]
683− => TableExpression params schema tables
684− -> Selection params schema columns
685−starFrom tabs = UnsafeSelection $ "* FROM " <> renderTableExpression tabs
659+newtype Query
660+ (schema :: [(Symbol,[(Symbol,ColumnType)])])
661+ (params :: [ColumnType])
662+ (columns :: [(Symbol,ColumnType)])
663+ = UnsafeQuery { renderQuery :: ByteString }
664+
665+query
666+ :: Query schema params columns
667+ -> DataManipulation schema params columns
668+query q = UnsafeDataManipulation $ renderQuery q <> ";"
669+
670+union, unionAll, intersect, intersectAll, except, exceptAll
671+ :: Query schema params columns
672+ -> Query schema params columns
673+ -> Query schema params columns
674+q1 `union` q2 = UnsafeQuery $
675+ renderQuery q1 <> " UNION " <> renderQuery q2
676+q1 `unionAll` q2 = UnsafeQuery $
677+ renderQuery q1 <> " UNION ALL " <> renderQuery q2
678+q1 `intersect` q2 = UnsafeQuery $
679+ renderQuery q1 <> " INTERSECT " <> renderQuery q2
680+q1 `intersectAll` q2 = UnsafeQuery $
681+ renderQuery q1 <> " INTERSECT ALL " <> renderQuery q2
682+q1 `except` q2 = UnsafeQuery $
683+ renderQuery q1 <> " EXCEPT " <> renderQuery q2
684+q1 `exceptAll` q2 = UnsafeQuery $
685+ renderQuery q1 <> " EXCEPT ALL " <> renderQuery q2
686686
687−dotStarFrom
688− :: HasTable table tables columns
689− => Alias table
690− -> TableExpression params schema tables
691− -> Selection params schema columns
692−table `dotStarFrom` tables = UnsafeSelection $
693− renderAlias table <> ".* FROM " <> renderTableExpression tables
687+{-----------------------------------------
688+SELECT statements
689+-----------------------------------------}
694690
695−from
691+select
696692 :: SListI columns
697693 => NP (Aliased (Expression params tables)) columns
698694 -> TableExpression params schema tables
699− -> Selection params schema columns
700−list `from` tabs = UnsafeSelection $
701− renderList list <> " FROM " <> renderTableExpression tabs
695+ -> Query schema params columns
696+select list tabs = UnsafeQuery $
697+ "SELECT " <> renderList list <> " " <> renderTableExpression tabs
702698 where
703699 renderList
704700 = ByteString.intercalate ", "
705701 . hcollapse
706702 . hmap (K . renderAliased renderExpression)
707703
708−select
709− :: Selection params schema columns
710− -> Statement params columns schema schema
711−select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
704+selectStar
705+ :: (tables ~ '[table ::: columns])
706+ => TableExpression params schema tables
707+ -> Query schema params columns
708+selectStar tabs = UnsafeQuery $ "SELECT * " <> renderTableExpression tabs
712709
713−subselect
714− :: Aliased (Selection params schema) table
715− -> TableExpression params schema '[table]
716−subselect selection = join (Subselect selection)
710+selectDotStar
711+ :: HasTable table tables columns
712+ => Alias table
713+ -> TableExpression params schema tables
714+ -> Query schema params columns
715+selectDotStar table tables = UnsafeQuery $
716+ "SELECT " <> renderAlias table <> ".* " <> renderTableExpression tables
717717
718718{-----------------------------------------
719719CREATE statements
@@ -723,8 +723,8 @@ createTable
723723 :: (KnownSymbol table, SListI columns)
724724 => Alias table
725725 -> NP (Aliased TypeExpression) columns
726− -> Statement '[] '[] schema (Create table columns schema)
727−createTable table columns = UnsafeStatement $ mconcat
726+ -> DataDefinition schema (Create table columns schema)
727+createTable table columns = UnsafeDataDefinition $ mconcat
728728 [ "CREATE TABLE "
729729 , renderAlias table
730730 , " ("
@@ -744,9 +744,8 @@ DROP statements
744744dropTable
745745 :: KnownSymbol table
746746 => Alias table
747− -> Statement '[] '[] schema (Drop table schema)
748−dropTable table = UnsafeStatement $
749− "DROP TABLE " <> renderAlias table <> ";"
747+ -> DataDefinition schema (Drop table schema)
748+dropTable table = UnsafeDataDefinition $ "DROP TABLE " <> renderAlias table <> ";"
750749
751750{-----------------------------------------
752751ALTER statements
@@ -756,8 +755,8 @@ alterTable
756755 :: HasTable table schema columns0
757756 => Alias table
758757 -> AlterTable columns0 columns1
759− -> Statement '[] '[] schema (Alter table schema columns1)
760−alterTable table alteration = UnsafeStatement $
758+ -> DataDefinition schema (Alter table schema columns1)
759+alterTable table alteration = UnsafeDataDefinition $
761760 "ALTER TABLE "
762761 <> renderAlias table
763762 <> " "
@@ -768,8 +767,8 @@ alterTableRename
768767 :: (KnownSymbol table0, KnownSymbol table1)
769768 => Alias table0
770769 -> Alias table1
771− -> Statement '[] '[] schema (Rename table0 table1 schema)
772−alterTableRename table0 table1 = UnsafeStatement $
770+ -> DataDefinition schema (Rename table0 table1 schema)
771+alterTableRename table0 table1 = UnsafeDataDefinition $
773772 "ALTER TABLE "
774773 <> renderAlias table0
775774 <> " RENAME TO "
@@ -862,8 +861,8 @@ insertInto
862861 :: (SListI columns, HasTable table schema columns)
863862 => Alias table
864863 -> NP (Aliased (Expression params '[])) columns
865− -> Statement params '[] schema schema
866−insertInto table expressions = UnsafeStatement $ "INSERT INTO "
864+ -> DataManipulation schema params '[]
865+insertInto table expressions = UnsafeDataManipulation $ "INSERT INTO "
867866 <> renderAlias table
868867 <> " (" <> ByteString.intercalate ", " aliases
869868 <> ") VALUES ("
@@ -882,9 +881,9 @@ insertIntoReturning
882881 => Alias table
883882 -> NP (Aliased (Expression params '[])) columns
884883 -> NP (Aliased (Expression params '[table ::: columns])) results
885− -> Statement params results schema schema
884+ -> DataManipulation schema params results
886885insertIntoReturning table inserts results
887− = UnsafeStatement . mconcat $
886+ = UnsafeDataManipulation . mconcat $
888887 [ "INSERT INTO "
889888 , renderAlias table
890889 , " (" <> ByteString.intercalate ", " aliases
@@ -929,9 +928,9 @@ update
929928 :: (HasTable table schema columns, SListI columns)
930929 => Alias table
931930 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
932− -> Predicate params '[table ::: columns]
933− -> Statement params '[] schema schema
934−update table columns wh = UnsafeStatement $ mconcat
931+ -> Condition params '[table ::: columns]
932+ -> DataManipulation schema params '[]
933+update table columns wh = UnsafeDataManipulation $ mconcat
935934 [ "UPDATE "
936935 , renderAlias table
937936 , " SET "
@@ -944,10 +943,10 @@ updateReturning
944943 :: (SListI columns, SListI results, HasTable table schema columns)
945944 => Alias table
946945 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
947− -> Predicate params '[table ::: columns]
946+ -> Condition params '[table ::: columns]
948947 -> NP (Aliased (Expression params '[table ::: columns])) results
949− -> Statement params results schema schema
950−updateReturning table updates wh results = UnsafeStatement $ mconcat
948+ -> DataManipulation schema params results
949+updateReturning table updates wh results = UnsafeDataManipulation $ mconcat
951950 [ "UPDATE "
952951 , renderAlias table
953952 , " SET "
@@ -968,9 +967,9 @@ upsertInto
968967 => Alias table
969968 -> NP (Aliased (Expression params '[])) columns
970969 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
971− -> Predicate params '[table ::: columns]
972− -> Statement params '[] schema schema
973−upsertInto table inserts updates wh = UnsafeStatement . mconcat $
970+ -> Condition params '[table ::: columns]
971+ -> DataManipulation schema params '[]
972+upsertInto table inserts updates wh = UnsafeDataManipulation . mconcat $
974973 [ "INSERT INTO "
975974 , renderAlias table
976975 , " (" <> ByteString.intercalate ", " aliases
@@ -995,11 +994,11 @@ upsertIntoReturning
995994 => Alias table
996995 -> NP (Aliased (Expression params '[])) columns
997996 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
998− -> Predicate params '[table ::: columns]
997+ -> Condition params '[table ::: columns]
999998 -> NP (Aliased (Expression params '[table ::: columns])) results
1000− -> Statement params results schema schema
999+ -> DataManipulation schema params results
10011000upsertIntoReturning table inserts updates wh results =
1002− UnsafeStatement . mconcat $
1001+ UnsafeDataManipulation . mconcat $
10031002 [ "INSERT INTO "
10041003 , renderAlias table
10051004 , " (" <> ByteString.intercalate ", " aliases
@@ -1032,9 +1031,9 @@ DELETE statements
10321031deleteFrom
10331032 :: HasTable table schema columns
10341033 => Alias table
1035− -> Predicate params '[table ::: columns]
1036− -> Statement params '[] schema schema
1037−deleteFrom table wh = UnsafeStatement $ mconcat
1034+ -> Condition params '[table ::: columns]
1035+ -> DataManipulation schema params '[]
1036+deleteFrom table wh = UnsafeDataManipulation $ mconcat
10381037 [ "DELETE FROM "
10391038 , renderAlias table
10401039 , " WHERE ", renderExpression wh, ";"