on dev help sign in
haddocks
b9d9c18Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+24−5
@@ -36,7 +36,15 @@ module Squeal.PostgreSQL.Expression
36 Expression (..)
36 Expression (..)
37 , Expr
37 , Expr
38 , Operator
38 , Operator
39+ , unsafeBinaryOp
39 , (:-->)
40 , (:-->)
41+ , unsafeUnaryOpL
42+ , unsafeUnaryOpR
43+ , unsafeFunction
44+ , FunctionHom
45+ , unsafeFunctionHom
46+ , FunctionHet
47+ , unsafeFunctionHet
40 , HasParameter (parameter)
48 , HasParameter (parameter)
41 , param
49 , param
42 -- ** Null
50 -- ** Null
@@ -56,11 +64,6 @@ module Squeal.PostgreSQL.Expression
56 , field
64 , field
57 , PGSubset (..)
65 , PGSubset (..)
58 -- ** Functions
66 -- ** Functions
59− , unsafeBinaryOp
60− , unsafeUnaryOpL
61− , unsafeUnaryOpR
62− , unsafeFunction
63− , unsafeFunctionHet
64 , atan2_
67 , atan2_
65 , cast
68 , cast
66 , quot_
69 , quot_
@@ -329,6 +332,12 @@ type (:-->) x y
329 -> Expression outer grp commons schemas params from y
332 -> Expression outer grp commons schemas params from y
330 -- ^ output
333 -- ^ output
331
334
335+{- | A `RankNType` for functions with a fixed-length list of heterogeneous arguments.
336+Use the `:*` operator to end your argument lists, like so.
337+
338+>>> printSQL (unsafeFunctionHet "fun" (true :* false :* localTime *: true))
339+fun(TRUE, FALSE, LOCALTIME, TRUE)
340+-}
332type FunctionHet xs y
341type FunctionHet xs y
333 = forall outer grp commons schemas params from
342 = forall outer grp commons schemas params from
334 . NP (Expression outer grp commons schemas params from) xs
343 . NP (Expression outer grp commons schemas params from) xs
@@ -336,6 +345,9 @@ type FunctionHet xs y
336 -> Expression outer grp commons schemas params from y
345 -> Expression outer grp commons schemas params from y
337 -- ^ output
346 -- ^ output
338
347
348+{- | A `RankNType` for functions with a variable-length list of
349+homogeneous arguments and at least 1 more argument.
350+-}
339type FunctionHom x0 x1 y
351type FunctionHom x0 x1 y
340 = forall outer grp commons schemas params from
352 = forall outer grp commons schemas params from
341 . [Expression outer grp commons schemas params from x0]
353 . [Expression outer grp commons schemas params from x0]
@@ -345,6 +357,9 @@ type FunctionHom x0 x1 y
345 -> Expression outer grp commons schemas params from y
357 -> Expression outer grp commons schemas params from y
346 -- ^ output
358 -- ^ output
347
359
360+{- | >>> printSQL (unsafeFunctionHom "greatest" [true, null_] false)
361+greatest(TRUE, NULL, FALSE)
362+-}
348unsafeFunctionHom :: ByteString -> FunctionHom x0 x1 y
363unsafeFunctionHom :: ByteString -> FunctionHom x0 x1 y
349unsafeFunctionHom fun xs x = UnsafeExpression $ fun <> parenthesized
364unsafeFunctionHom fun xs x = UnsafeExpression $ fun <> parenthesized
350 (commaSeparated (renderSQL <$> xs) <> ", " <> renderSQL x)
365 (commaSeparated (renderSQL <$> xs) <> ", " <> renderSQL x)
@@ -654,6 +669,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
654unsafeUnaryOpL :: ByteString {- ^ operator -} -> x :--> y
669unsafeUnaryOpL :: ByteString {- ^ operator -} -> x :--> y
655unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
670unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
656
671
672+-- | >>> printSQL $ true & unsafeUnaryOpR "IS NOT TRUE"
673+-- (TRUE IS NOT TRUE)
657unsafeUnaryOpR :: ByteString {- ^ operator -} -> x :--> y
674unsafeUnaryOpR :: ByteString {- ^ operator -} -> x :--> y
658unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
675unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
659
676
@@ -663,6 +680,8 @@ unsafeFunction :: ByteString {- ^ function -} -> x :--> y
663unsafeFunction fun x = UnsafeExpression $
680unsafeFunction fun x = UnsafeExpression $
664 fun <> parenthesized (renderSQL x)
681 fun <> parenthesized (renderSQL x)
665
682
683+-- | >>> printSQL $ unsafeFunctionHet "f" (currentTime :* localTimestamp :* false *: litChar 'a')
684+-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, E'a')
666unsafeFunctionHet
685unsafeFunctionHet
667 :: SListI xs
686 :: SListI xs
668 => ByteString {- ^ function -}
687 => ByteString {- ^ function -}