on dev help sign in
array indexing function
d4b4cddEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9
@@ -45,6 +45,7 @@ module Squeal.PostgreSQL.Expression
45 , nullIf
45 , nullIf
46 -- ** Collections
46 -- ** Collections
47 , array
47 , array
48+ , index
48 , row
49 , row
49 , field
50 , field
50 -- ** Functions
51 -- ** Functions
@@ -195,6 +196,7 @@ import Data.Semigroup hiding (All)
195import qualified Data.Aeson as JSON
196import qualified Data.Aeson as JSON
196import Data.Ratio
197import Data.Ratio
197import Data.String
198import Data.String
199+import Data.Word
198import Generics.SOP hiding (from)
200import Generics.SOP hiding (from)
199import GHC.OverloadedLabels
201import GHC.OverloadedLabels
200import GHC.TypeLits
202import GHC.TypeLits
@@ -444,6 +446,13 @@ array
444array xs = UnsafeExpression $
446array xs = UnsafeExpression $
445 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
447 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
446
448
449+index
450+ :: Word64
451+ -> Expression schema from grouping params (nullity ('PGvararray ty))
452+ -> Expression schema from grouping params (NullifyType ty)
453+index n expr = UnsafeExpression $
454+ parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
455+
447instance (KnownSymbol label, label `In` labels) => IsPGlabel label
456instance (KnownSymbol label, label `In` labels) => IsPGlabel label
448 (Expression schema from grouping params (nullity ('PGenum labels))) where
457 (Expression schema from grouping params (nullity ('PGenum labels))) where
449 label = UnsafeExpression $ renderLabel (PGlabel @label)
458 label = UnsafeExpression $ renderLabel (PGlabel @label)