on dev help sign in
Additionally
commit41bf0a94acceecdcaeba2d1213a571fd34972614 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateFri 12 Apr 2019, 10:50 (8 years ago) parentd30ec04
3 files changed+22−28
squeal-postgresql/src/Squeal/PostgreSQL/List.hs+10−8 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs−15 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+12−5
squeal-postgresql/src/Squeal/PostgreSQL/List.hs+10−8
@@ -19,8 +19,8 @@ module Squeal.PostgreSQL.List
1919 ( SOP.NP (..)
2020 , (*:)
2121 , Join
22− , (+++)
2322 , disjoin
23+ , Additionally (..)
2424 , AlignedList (..)
2525 , single
2626 , extractList
@@ -31,6 +31,7 @@ module Squeal.PostgreSQL.List
3131 ) where
3232
3333import Control.Category
34+import Data.Function ((&))
3435import Data.Kind
3536import Data.Type.Bool
3637import GHC.TypeLits
@@ -45,13 +46,6 @@ type family Join xs ys where
4546 Join '[] ys = ys
4647 Join (x ': xs) ys = x ': Join xs ys
4748
48−-- | Concatenate `NP` lists.
49−(+++) :: NP f xs -> NP f ys -> NP f (Join xs ys)
50−xs +++ ys = case xs of
51− Nil -> ys
52− x :* xs' -> x :* (xs' +++ ys)
53−infixr 5 +++
54−
5549-- | `disjoin` is a utility function for splitting an `NP` list into pieces.
5650disjoin
5751 :: forall xs ys expr. SListI xs
@@ -62,6 +56,14 @@ disjoin = case sList @xs of
6256 SCons -> \(x :* xsys) ->
6357 case disjoin xsys of (xs,ys) -> (x :* xs, ys)
6458
59+class Additionally expr where
60+ also :: expr ys -> expr xs -> expr (Join xs ys)
61+
62+instance Additionally (NP expr) where
63+ also ys = \case
64+ Nil -> ys
65+ x :* xs -> x :* (xs & also ys)
66+
6567-- | An `AlignedList` is a type-aligned list or free category.
6668data AlignedList p x0 x1 where
6769 Done :: AlignedList p x x
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs−15
@@ -51,7 +51,6 @@ module Squeal.PostgreSQL.Manipulation
5151 -- * Delete
5252 , deleteFrom
5353 , deleteFrom_
54− , also
5554 ) where
5655
5756import Control.DeepSeq
@@ -575,17 +574,3 @@ deleteFrom_
575574 -- ^ condition under which to delete a row
576575 -> Manipulation commons schemas params '[]
577576deleteFrom_ tab wh = deleteFrom tab NoUsing wh (Returning_ Nil)
578−
579−-- | This has the behaviour of a cartesian product, taking all
580−-- possible combinations between @left@ and @right@ - exactly like a
581−-- `crossJoin`. Used when no `crossJoin` syntax is required but simply
582−-- a comma separated list of tables. Typical case is the `UsingClause`
583−-- of a `deleteFrom` query.
584−also
585− :: FromClause outer commons schemas params right
586− -- ^ right
587− -> FromClause outer commons schemas params left
588− -- ^ left
589− -> FromClause outer commons schemas params (Join left right)
590−also right left = UnsafeFromClause $
591− renderSQL left <> "," <+> renderSQL right
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+12−5
@@ -426,6 +426,8 @@ data Selection outer commons grp schemas params from row where
426426 => NP (Aliased (WindowFunction outer commons grp schemas params from)) row
427427 -> WindowDefinition outer commons grp schemas params from
428428 -> Selection outer commons grp schemas params from row
429+instance Additionally (Selection outer commons grp schemas params from) where
430+ also = Also
429431instance (KnownSymbol col, row ~ '[col ::: ty])
430432 => Aliasable col
431433 (Expression outer commons grp schemas params from ty)
@@ -921,11 +923,16 @@ common
921923common (cte `As` alias) = UnsafeFromClause $
922924 renderSQL cte <+> "AS" <+> renderSQL alias
923925
924−{- | @left & crossJoin right@. For every possible combination of rows from
925− @left@ and @right@ (i.e., a Cartesian product), the joined table will contain
926− a row consisting of all columns in @left@ followed by all columns in @right@.
927− If the tables have @n@ and @m@ rows respectively, the joined table will
928− have @n * m@ rows.
926+instance Additionally (FromClause outer commons schemas params) where
927+ also right left = UnsafeFromClause $
928+ renderSQL left <> ", " <> renderSQL right
929+
930+{- |
931+@left & crossJoin right@. For every possible combination of rows from
932+@left@ and @right@ (i.e., a Cartesian product), the joined table will contain
933+a row consisting of all columns in @left@ followed by all columns in @right@.
934+If the tables have @n@ and @m@ rows respectively, the joined table will
935+have @n * m@ rows.
929936-}
930937crossJoin
931938 :: FromClause outer commons schemas params right