on dev help sign in
Merge pull request #104 from morphismtech/dev-unnest
3b9e0f4Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+8
@@ -47,6 +47,7 @@ module Squeal.PostgreSQL.Expression
47 , nullIf
47 , nullIf
48 -- ** Collections
48 -- ** Collections
49 , array
49 , array
50+ , cardinality
50 , index
51 , index
51 , row
52 , row
52 , field
53 , field
@@ -483,6 +484,13 @@ array
483array xs = UnsafeExpression $
484array xs = UnsafeExpression $
484 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
485 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
485
486
487+-- | >>> printSQL $ cardinality (array [null_, false, true])
488+-- cardinality(ARRAY[NULL, FALSE, TRUE])
489+cardinality
490+ :: Expression outer grp commons schemas params from (nullity ('PGvararray ty))
491+ -> Expression outer grp commons schemas params from (nullity 'PGint8)
492+cardinality = unsafeFunction "cardinality"
493+
486-- | >>> printSQL $ array [null_, false, true] & index 2
494-- | >>> printSQL $ array [null_, false, true] & index 2
487-- (ARRAY[NULL, FALSE, TRUE])[2]
495-- (ARRAY[NULL, FALSE, TRUE])[2]
488index
496index
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7
@@ -52,6 +52,8 @@ module Squeal.PostgreSQL.Query
52 -- ** With
52 -- ** With
53 , With (..)
53 , With (..)
54 , CommonTableExpression (..)
54 , CommonTableExpression (..)
55+ -- ** Unnest
56+ , unnest
55 -- ** Json
57 -- ** Json
56 , jsonEach
58 , jsonEach
57 , jsonbEach
59 , jsonbEach
@@ -718,6 +720,11 @@ unsafeSetOfFunction
718unsafeSetOfFunction fun expr = UnsafeQuery $
720unsafeSetOfFunction fun expr = UnsafeQuery $
719 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
721 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
720
722
723+unnest
724+ :: Expression outer 'Ungrouped commons schemas params '[] (nullity ('PGvararray ty))
725+ -> Query outer commons schemas params '[ "unnest" ::: ty ]
726+unnest = unsafeSetOfFunction "unnest"
727+
721-- | Expands the outermost JSON object into a set of key/value pairs.
728-- | Expands the outermost JSON object into a set of key/value pairs.
722jsonEach
729jsonEach
723 :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object
730 :: Expression outer 'Ungrouped commons schemas params '[] (nullity 'PGjson) -- ^ json object