on dev help sign in
function with heterogeneous arguments
commitc25657ea3d3a05fa1dd54ddc33ae5952febef5fe authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateFri 15 Mar 2019, 16:54 (8 years ago) parent8df5d8d
1 file changed+22−29
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22−29
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22−29
@@ -35,6 +35,7 @@ module Squeal.PostgreSQL.Expression
3535 ( -- * Expression
3636 Expression (..)
3737 , Operator
38+ , (:-->)
3839 , HasParameter (parameter)
3940 , param
4041 -- ** Null
@@ -56,7 +57,6 @@ module Squeal.PostgreSQL.Expression
5657 , unsafeBinaryOp
5758 , unsafeUnaryOp
5859 , unsafeFunction
59− , unsafeFunction2
6060 , unsafeVariadicFunction
6161 , atan2_
6262 , cast
@@ -298,6 +298,11 @@ type (:-->) x y
298298 . Expression outer grp commons schemas params from x
299299 -> Expression outer grp commons schemas params from y
300300
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+
301306{- | A `HasParameter` constraint is used to indicate a value that is
302307supplied externally to a SQL statement.
303308`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -645,14 +650,12 @@ unsafeFunction :: ByteString {- ^ function -} -> x :--> y
645650unsafeFunction fun x = UnsafeExpression $
646651 fun <> parenthesized (renderSQL x)
647652
648−unsafeFunction2
649− :: ByteString
650− -- ^ function
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 $
655− fun <> parenthesized (commaSeparated [renderSQL x1, renderSQL x2])
653+unsafeFunctionHet
654+ :: SListI xs
655+ => ByteString {- ^ function -}
656+ -> FunctionHet xs y
657+unsafeFunctionHet fun xs = UnsafeExpression $
658+ fun <> parenthesized (renderCommaSeparated renderSQL xs)
656659
657660-- | Helper for defining variadic functions.
658661unsafeVariadicFunction
@@ -1533,38 +1536,28 @@ numnode :: nullity 'PGtsquery :--> nullity 'PGint4
15331536numnode = unsafeFunction "numnode"
15341537
15351538plainToTSquery
1536− :: Expression outer grp commons schemas params from (nullity 'PGtext)
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"
1539+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1540+plainToTSquery = unsafeFunctionHet "plainto_tsquery"
15401541
15411542phraseToTSquery
1542− :: Expression outer grp commons schemas params from (nullity 'PGtext)
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"
1543+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1544+phraseToTSquery = unsafeFunctionHet "phraseto_tsquery"
15461545
15471546websearchToTSquery
1548− :: Expression outer grp commons schemas params from (nullity 'PGtext)
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"
1547+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1548+websearchToTSquery = unsafeFunctionHet "websearch_to_tsquery"
15521549
15531550queryTree :: nullity 'PGtsquery :--> nullity 'PGtext
15541551queryTree = unsafeFunction "query_tree"
15551552
15561553toTSquery
1557− :: Expression outer grp commons schemas params from (nullity 'PGtext)
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"
1554+ :: FunctionHet '[nullity 'PGtext, nullity 'PGtext] (nullity 'PGtsquery)
1555+toTSquery = unsafeFunctionHet "to_tsquery"
15611556
15621557toTSvector
15631558 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
1564− => Expression outer grp commons schemas params from (nullity 'PGtext)
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"
1559+ => FunctionHet '[nullity 'PGtext, nullity ty] (nullity 'PGtsquery)
1560+toTSvector = unsafeFunctionHet "to_tsvector"
15681561
15691562{-----------------------------------------
15701563aggregation