@@ -53,6 +53,9 @@ module Squeal.PostgreSQL.Definition
53 , createOrReplaceFunction
53 , createOrReplaceFunction
54 , createSetFunction
54 , createSetFunction
55 , createOrReplaceSetFunction
55 , createOrReplaceSetFunction
56 , TableConstraintExpression (..)
59 , TableConstraintExpression (..)
@@ -71,6 +74,7 @@ module Squeal.PostgreSQL.Definition
71 , dropType
74 , dropType
72 , dropIndex
75 , dropIndex
73 , dropFunction
76 , dropFunction
74 -- ** Alter
78 -- ** Alter
75 , alterTable
79 , alterTable
76 , alterTableRename
80 , alterTableRename
@@ -1215,13 +1219,74 @@ createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
1215 renderRet :: Aliased (TypeExpression s) r -> ByteString
1219 renderRet :: Aliased (TypeExpression s) r -> ByteString
1216 renderRet (ty `As` col) = renderSQL col <+> renderSQL ty
1220 renderRet (ty `As` col) = renderSQL col <+> renderSQL ty
1223+ :: ( Has sch schemas schema
1224+ , Has fun schema ('Function '[x,y] ('Returns z))
1228+ -> TypeExpression schemas x
1229+ -> TypeExpression schemas y
1230+ -> Definition schemas
1231+ (Alter sch (Create op ('Operator ('BinaryOp x y z)) schema) schemas)
1232+createBinaryOp op fun x y = UnsafeDefinition $
1233+ "CREATE" <+> "OPERATOR" <+> renderSQL op
1234+ <+> parenthesized (commaSeparated opdef)
1237+ [ "FUNCTION" <+> "=" <+> renderSQL fun
1238+ , "LEFTARG" <+> "=" <+> renderSQL x
1239+ , "RIGHTARG" <+> "=" <+> renderSQL y ]
1242+ :: ( Has sch schemas schema
1243+ , Has fun schema ('Function '[x] ('Returns y))
1247+ -> TypeExpression schemas x
1248+ -> Definition schemas
1249+ (Alter sch (Create op ('Operator ('UnaryOpL x y)) schema) schemas)
1250+createUnaryOpL op fun x = UnsafeDefinition $
1251+ "CREATE" <+> "OPERATOR" <+> renderSQL op
1252+ <+> parenthesized (commaSeparated opdef)
1255+ [ "FUNCTION" <+> "=" <+> renderSQL fun
1256+ , "RIGHTARG" <+> "=" <+> renderSQL x ]
1259+ :: ( Has sch schemas schema
1260+ , Has fun schema ('Function '[x] ('Returns y))
1264+ -> TypeExpression schemas x
1265+ -> Definition schemas
1266+ (Alter sch (Create op ('Operator ('UnaryOpR x y)) schema) schemas)
1267+createUnaryOpR op fun x = UnsafeDefinition $
1268+ "CREATE" <+> "OPERATOR" <+> renderSQL op
1269+ <+> parenthesized (commaSeparated opdef)
1272+ [ "FUNCTION" <+> "=" <+> renderSQL fun
1273+ , "LEFTARG" <+> "=" <+> renderSQL x ]
1218dropFunction
1275dropFunction
1219 :: (Has sch schemas schema, Has fun schema ('Function args ret))
1276 :: (Has sch schemas schema, Has fun schema ('Function args ret))
1220 => QualifiedAlias sch fun
1277 => QualifiedAlias sch fun
1221 -- ^ name of the user defined function
1278 -- ^ name of the user defined function
1222− -> Definition schemas (Alter sch (Drop ix schema) schemas)
1279+ -> Definition schemas (Alter sch (Drop fun schema) schemas)
1223dropFunction fun = UnsafeDefinition $
1280dropFunction fun = UnsafeDefinition $
1224− "DROP" <+> "Function" <+> renderSQL fun <> ";"
1281+ "DROP" <+> "FUNCTION" <+> renderSQL fun <> ";"
1284+ :: (Has sch schemas schema, Has op schema ('Operator oper))
1285+ => QualifiedAlias sch op
1286+ -- ^ name of the user defined operator
1287+ -> Definition schemas (Alter sch (Drop op schema) schemas)
1288+dropOperator op = UnsafeDefinition $
1289+ "DROP" <+> "OPERATOR" <+> renderSQL op <> ";"
1226newtype FunctionDefinition schemas args ret = UnsafeFunctionDefinition
1291newtype FunctionDefinition schemas args ret = UnsafeFunctionDefinition
1227 { renderFunctionDefinition :: ByteString }
1292 { renderFunctionDefinition :: ByteString }