{-# LANGUAGE
AllowAmbiguousTypes
, DataKinds
, FlexibleContexts
, OverloadedStrings
, PolyKinds
, RankNTypes
, ScopedTypeVariables
, TypeApplications
, TypeOperators
#-}
module Squeal.PostgreSQL.Expression.SetOf
( generateSeries
, generateSeriesStep
, generateSeriesTimestamp
, SetOfFunction
, unsafeSetOfFunction
, SetOfFunctionN
, unsafeSetOfFunctionN
) where
import GHC.TypeLits
import qualified Generics.SOP as SOP
import Squeal.PostgreSQL.Alias
import Squeal.PostgreSQL.Expression
import Squeal.PostgreSQL.List
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Query
import Squeal.PostgreSQL.Schema
type SetOfFunction fun ty setof
= forall outer commons schemas params
. Expression outer commons 'Ungrouped schemas params '[] ty
-> FromClause outer commons schemas params '[fun ::: setof]
unsafeSetOfFunction
:: forall fun ty setof. KnownSymbol fun
=> SetOfFunction fun ty setof
unsafeSetOfFunction x = UnsafeFromClause $
renderSymbol @fun <> parenthesized (renderSQL x)
type SetOfFunctionN fun tys setof
= forall outer commons schemas params
. NP (Expression outer commons 'Ungrouped schemas params '[]) tys
-> FromClause outer commons schemas params '[fun ::: setof]
unsafeSetOfFunctionN
:: forall fun tys setof. (SOP.SListI tys, KnownSymbol fun)
=> SetOfFunctionN fun tys setof
unsafeSetOfFunctionN xs = UnsafeFromClause $
renderSymbol @fun <> parenthesized (renderCommaSeparated renderSQL xs)
generateSeries
:: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
=> SetOfFunctionN "generate_series" '[ null ty, null ty]
'["generate_series" ::: null ty]
generateSeries = unsafeSetOfFunctionN
generateSeriesStep
:: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
=> SetOfFunctionN "generate_series" '[null ty, null ty, null ty]
'["generate_series" ::: null ty]
generateSeriesStep = unsafeSetOfFunctionN
generateSeriesTimestamp
:: ty `In` '[ 'PGtimestamp, 'PGtimestamptz]
=> SetOfFunctionN "generate_series" '[null ty, null ty, null 'PGinterval]
'["generate_series" ::: null ty]
generateSeriesTimestamp = unsafeSetOfFunctionN