on dev help sign in
function DB types
commit66d88ed544607cc2cfb0cf95a38d343bc11f3b33 authorEitan Chatav <eitan@EEM109LMBP-1.local> dateTue 3 Sep 2019, 18:13 (7 years ago) parent3bd8b61
1 file changed+31−9
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+31−9
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+31−9
@@ -35,6 +35,7 @@ module Squeal.PostgreSQL.Expression
3535 Expression (..)
3636 , Expr
3737 , (:-->)
38+ , FunctionDB
3839 , unsafeFunction
3940 , function
4041 , unsafeUnaryOpL
@@ -42,11 +43,13 @@ module Squeal.PostgreSQL.Expression
4243 , unsafeUnaryOpR
4344 , unaryOpR
4445 , Operator
46+ , OperatorDB
4547 , unsafeBinaryOp
4648 , binaryOp
4749 , FunctionVar
4850 , unsafeFunctionVar
4951 , FunctionN
52+ , FunctionNDB
5053 , unsafeFunctionN
5154 , functionN
5255 , PGSubset (..)
@@ -142,6 +145,15 @@ type Operator x1 x2 y
142145 -> Expression outer commons grp schemas params from y
143146 -- ^ output
144147
148+type OperatorDB schemas x1 x2 y
149+ = forall outer commons grp params from
150+ . Expression outer commons grp schemas params from x1
151+ -- ^ left input
152+ -> Expression outer commons grp schemas params from x2
153+ -- ^ right input
154+ -> Expression outer commons grp schemas params from y
155+ -- ^ output
156+
145157-- | A @RankNType@ for functions with a single argument.
146158-- These could be either function calls or unary operators.
147159-- This is a subtype of the usual Haskell function type `Prelude.->`,
@@ -154,6 +166,13 @@ type (:-->) x y
154166 -> Expression outer commons grp schemas params from y
155167 -- ^ output
156168
169+type FunctionDB schemas x y
170+ = forall outer commons grp params from
171+ . Expression outer commons grp schemas params from x
172+ -- ^ input
173+ -> Expression outer commons grp schemas params from y
174+ -- ^ output
175+
157176{- | A @RankNType@ for functions with a fixed-length list of heterogeneous arguments.
158177Use the `*:` operator to end your argument lists, like so.
159178
@@ -167,6 +186,13 @@ type FunctionN xs y
167186 -> Expression outer commons grp schemas params from y
168187 -- ^ output
169188
189+type FunctionNDB schemas xs y
190+ = forall outer commons grp params from
191+ . NP (Expression outer commons grp schemas params from) xs
192+ -- ^ inputs
193+ -> Expression outer commons grp schemas params from y
194+ -- ^ output
195+
170196{- | A @RankNType@ for functions with a variable-length list of
171197homogeneous arguments and at least 1 more argument.
172198-}
@@ -294,7 +320,7 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
294320
295321binaryOp
296322 :: (Has sch schemas schema, Has op schema ('Operator ('BinaryOp x1 x2 y)))
297− => Alias op -> Operator x1 x2 y
323+ => Alias op -> OperatorDB schemas x1 x2 y
298324binaryOp = unsafeBinaryOp . renderSQL
299325
300326-- | >>> printSQL $ unsafeUnaryOpL "NOT" true
@@ -304,7 +330,7 @@ unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
304330
305331unaryOpL
306332 :: (Has sch schemas schema, Has op schema ('Operator ('UnaryOpL x y)))
307− => Alias op -> x :--> y
333+ => Alias op -> FunctionDB schemas x y
308334unaryOpL = unsafeUnaryOpL . renderSQL
309335
310336-- | >>> printSQL $ true & unsafeUnaryOpR "IS NOT TRUE"
@@ -314,7 +340,7 @@ unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
314340
315341unaryOpR
316342 :: (Has sch schemas schema, Has op schema ('Operator ('UnaryOpR x y)))
317− => Alias op -> x :--> y
343+ => Alias op -> FunctionDB schemas x y
318344unaryOpR = unsafeUnaryOpR . renderSQL
319345
320346-- | >>> printSQL $ unsafeFunction "f" true
@@ -326,9 +352,7 @@ unsafeFunction fun x = UnsafeExpression $
326352function
327353 :: (Has sch schemas schema, Has fun schema ('Function '[x] ('Returns y)))
328354 => QualifiedAlias sch fun
329− -> ( forall outer commons grp params from
330− . Expression outer commons grp schemas params from x
331− -> Expression outer commons grp schemas params from y )
355+ -> FunctionDB schemas x y
332356function = unsafeFunction . renderSQL
333357
334358-- | >>> printSQL $ unsafeFunctionN "f" (currentTime :* localTimestamp :* false *: literal 'a')
@@ -342,9 +366,7 @@ functionN
342366 , Has fun schema ('Function xs ('Returns y))
343367 , SListI xs )
344368 => QualifiedAlias sch fun
345− -> ( forall outer commons grp params from
346− . NP (Expression outer commons grp schemas params from) xs
347− -> Expression outer commons grp schemas params from y )
369+ -> FunctionNDB schemas xs y
348370functionN = unsafeFunctionN . renderSQL
349371
350372instance ty `In` PGNum