on dev help sign in
function with heterogeneous arguments
c25657eEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22−29
@@ -35,6 +35,7 @@ module Squeal.PostgreSQL.Expression
35 ( -- * Expression
35 ( -- * Expression
36 Expression (..)
36 Expression (..)
37 , Operator
37 , Operator
38+ , (:-->)
38 , HasParameter (parameter)
39 , HasParameter (parameter)
39 , param
40 , param
40 -- ** Null
41 -- ** Null
@@ -56,7 +57,6 @@ module Squeal.PostgreSQL.Expression
56 , unsafeBinaryOp
57 , unsafeBinaryOp
57 , unsafeUnaryOp
58 , unsafeUnaryOp
58 , unsafeFunction
59 , unsafeFunction
59− , unsafeFunction2
60 , unsafeVariadicFunction
60 , unsafeVariadicFunction
61 , atan2_
61 , atan2_
62 , cast
62 , cast
@@ -298,6 +298,11 @@ type (:-->) x y
298 . Expression outer grp commons schemas params from x
298 . Expression outer grp commons schemas params from x
299 -> Expression outer grp commons schemas params from y
299 -> Expression outer grp commons schemas params from y
300
300
301+type FunctionHet xs y
302+ = forall outer grp commons schemas params from
303+ . NP (Expression outer grp commons schemas params from) xs
304+ -> Expression outer grp commons schemas params from y
305+
301{- | A `HasParameter` constraint is used to indicate a value that is
306{- | A `HasParameter` constraint is used to indicate a value that is
302supplied externally to a SQL statement.
307supplied externally to a SQL statement.
303`Squeal.PostgreSQL.PQ.manipulateParams`,
308`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -645,14 +650,12 @@ unsafeFunction :: ByteString {- ^ function -} -> x :--> y
645unsafeFunction fun x = UnsafeExpression $
650unsafeFunction fun x = UnsafeExpression $
646 fun <> parenthesized (renderSQL x)
651 fun <> parenthesized (renderSQL x)
647
652
648−unsafeFunction2
653+unsafeFunctionHet
654+ :: SListI xs
649− :: ByteString
655+ => ByteString {- ^ function -}
650− -- ^ function
656+ -> FunctionHet xs y
651− -> Expression outer grp commons schemas params from ty1
652− -> Expression outer grp commons schemas params from ty2
653− -> Expression outer grp commons schemas params from ty
654−unsafeFunction2 fun x1 x2 = UnsafeExpression $
657+unsafeFunctionHet fun xs = UnsafeExpression $
655− fun <> parenthesized (commaSeparated [renderSQL x1, renderSQL x2])
658+ fun <> parenthesized (renderCommaSeparated renderSQL xs)
656
659
657-- | Helper for defining variadic functions.
660-- | Helper for defining variadic functions.
658unsafeVariadicFunction
661unsafeVariadicFunction
@@ -1533,38 +1536,28 @@ numnode :: nullity 'PGtsquery :--> nullity 'PGint4
1533numnode = unsafeFunction "numnode"
1536numnode = unsafeFunction "numnode"
1534
1537
1535plainToTSquery
1538plainToTSquery
1536− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1539+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1537− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1538− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1539−plainToTSquery = unsafeFunction2 "plainto_tsquery"
1540+plainToTSquery = unsafeFunctionHet "plainto_tsquery"
1540
1541
1541phraseToTSquery
1542phraseToTSquery
1542− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1543+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1543− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1544− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1545−phraseToTSquery = unsafeFunction2 "phraseto_tsquery"
1544+phraseToTSquery = unsafeFunctionHet "phraseto_tsquery"
1546
1545
1547websearchToTSquery
1546websearchToTSquery
1548− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1547+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1549− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1550− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1551−websearchToTSquery = unsafeFunction2 "websearch_to_tsquery"
1548+websearchToTSquery = unsafeFunctionHet "websearch_to_tsquery"
1552
1549
1553queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
1550queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
1554queryTree = unsafeFunction "query_tree"
1551queryTree = unsafeFunction "query_tree"
1555
1552
1556toTSquery
1553toTSquery
1557− :: Expression outer grp commons schemas params from (nullity 'PGtext)
1554+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1558− -> Expression outer grp commons schemas params from (nullity 'PGtext)
1559− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1560−toTSquery = unsafeFunction2 "to_tsquery"
1555+toTSquery = unsafeFunctionHet "to_tsquery"
1561
1556
1562toTSvector
1557toTSvector
1563 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1558 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1564− => Expression outer grp commons schemas params from (nullity 'PGtext)
1559+ => FunctionHet '[nullity 'PGtext, nullity ty] (nullity 'PGtsquery)
1565− -> Expression outer grp commons schemas params from (nullity ty)
1566− -> Expression outer grp commons schemas params from (nullity 'PGtsquery)
1567−toTSvector = unsafeFunction2 "to_tsvector"
1560+toTSvector = unsafeFunctionHet "to_tsvector"
1568
1561
1569{-----------------------------------------
1562{-----------------------------------------
1570aggregation
1563aggregation