on dev help sign in
functions
commit20cad4139f29891254a7cacfaf0a6dedaccdc5d6 authorEitan Chatav <eitan@EEM109LMBP-1.local> dateFri 30 Aug 2019, 15:27 (7 years ago) parentf57b03b
3 files changed+26
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+18 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+7 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+18
@@ -48,6 +48,7 @@ module Squeal.PostgreSQL.Definition
4848 , createDomain
4949 , createTypeRange
5050 , createIndex
51+ , createFunction
5152 , TableConstraintExpression (..)
5253 , check
5354 , unique
@@ -1112,6 +1113,23 @@ instance RenderSQL IndexMethod where
11121113 Gin -> "gin"
11131114 Brin -> "brin"
11141115
1116+createFunction
1117+ :: (Has sch schemas schema, KnownSymbol fun)
1118+ => QualifiedAlias sch fun
1119+ -> TypeExpression schemas arg
1120+ -> TypeExpression schemas ret
1121+ -> FunctionDefinition schemas arg ret
1122+ -> Definition schemas (Alter sch (Create fun ('Function arg ret) schema) schemas)
1123+createFunction fun arg ret fundef = UnsafeDefinition $
1124+ "CREATE" <+> "FUNCTION" <+> renderSQL fun <+> parenthesized (renderSQL arg)
1125+ <+> "RETURNS" <+> renderSQL ret <+> renderSQL fundef <> ";"
1126+
1127+newtype FunctionDefinition schemas arg ret = UnsafeFunctionDefinition
1128+ { renderFunctionDefinition :: ByteString }
1129+ deriving (Eq,Show,GHC.Generic,NFData)
1130+instance RenderSQL (FunctionDefinition schemas arg ret) where
1131+ renderSQL = renderFunctionDefinition
1132+
11151133-- |
11161134-- >>> printSQL (dropIndex #ix :: Definition (Public '["ix" ::: 'Index]) (Public '[]))
11171135-- DROP INDEX "ix";
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+7
@@ -36,6 +36,7 @@ module Squeal.PostgreSQL.Expression
3636 , Expr
3737 , (:-->)
3838 , unsafeFunction
39+ , function
3940 , unsafeUnaryOpL
4041 , unsafeUnaryOpR
4142 , Operator
@@ -303,6 +304,12 @@ unsafeFunction :: ByteString -> x :--> y
303304unsafeFunction fun x = UnsafeExpression $
304305 fun <> parenthesized (renderSQL x)
305306
307+function
308+ :: (Has sch schemas schema, Has fun schema ('Function x y))
309+ => QualifiedAlias sch fun
310+ -> x :--> y
311+function = unsafeFunction . renderSQL
312+
306313-- | >>> printSQL $ unsafeFunctionN "f" (currentTime :* localTimestamp :* false *: literal 'a')
307314-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, E'a')
308315unsafeFunctionN :: SListI xs => ByteString -> FunctionN xs y
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1
@@ -367,6 +367,7 @@ data SchemumType
367367 | View RowType
368368 | Typedef PGType
369369 | Index
370+ | Function NullityType NullityType
370371 | UnsafeSchemum Symbol
371372
372373{- | The schema of a database consists of a list of aliased,