on dev help sign in
drop functions and operators

some fixes

commit10c4aa6a3f84c9fcfdefd04f9b77a55386b7a406 authorEitan Chatav <eitan@EEM109LMBP-1.local> dateTue 24 Sep 2019, 09:06 (7 years ago) parent50bf2ad
2 files changed+30−13
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+26−9 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4−4
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+26−9
@@ -46,9 +46,9 @@ module Squeal.PostgreSQL.Definition
4646 , createTypeEnumFrom
4747 , createTypeComposite
4848 , createTypeCompositeFrom
49− , FieldTyped (..)
50− , createDomain
5149 , createTypeRange
50+ , createDomain
51+ , FieldTyped (..)
5252 , createIndex
5353 , createIndexIfNotExists
5454 , IndexMethod (..)
@@ -83,7 +83,9 @@ module Squeal.PostgreSQL.Definition
8383 , dropIndex
8484 , dropIndexIfExists
8585 , dropFunction
86+ , dropFunctionIfExists
8687 , dropOperator
88+ , dropOperatorIfExists
8789 -- ** Alter
8890 , alterTable
8991 , alterTableRename
@@ -931,7 +933,7 @@ in printSQL definition
931933CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
932934-}
933935createView
934− :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
936+ :: (Has sch schemas schema, KnownSymbol vw)
935937 => QualifiedAlias sch vw -- ^ the name of the view to add
936938 -> Query '[] '[] schemas '[] view -- ^ query
937939 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
@@ -939,9 +941,8 @@ createView alias query = UnsafeDefinition $
939941 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
940942 <+> renderQuery query <> ";"
941943
942−
943944createOrReplaceView
944− :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
945+ :: (Has sch schemas schema, KnownSymbol vw)
945946 => QualifiedAlias sch vw -- ^ the name of the view to add
946947 -> Query '[] '[] schemas '[] view -- ^ query
947948 -> Definition schemas (Alter sch (CreateOrReplace vw ('View view) schema) schemas)
@@ -1338,21 +1339,37 @@ createRightOp fun x = UnsafeDefinition $
13381339 , "LEFTARG" <+> "=" <+> renderSQL x ]
13391340
13401341dropFunction
1341− :: (Has sch schemas schema, Has fun schema ('Function (args '::--> ret)))
1342+ :: (Has sch schemas schema, KnownSymbol fun)
13421343 => QualifiedAlias sch fun
13431344 -- ^ name of the user defined function
1344− -> Definition schemas (Alter sch (Drop fun schema) schemas)
1345+ -> Definition schemas (Alter sch (DropSchemum fun 'Function schema) schemas)
13451346dropFunction fun = UnsafeDefinition $
13461347 "DROP" <+> "FUNCTION" <+> renderSQL fun <> ";"
13471348
1349+dropFunctionIfExists
1350+ :: (Has sch schemas schema, KnownSymbol fun)
1351+ => QualifiedAlias sch fun
1352+ -- ^ name of the user defined function
1353+ -> Definition schemas (Alter sch (DropSchemumIfExists fun 'Function schema) schemas)
1354+dropFunctionIfExists fun = UnsafeDefinition $
1355+ "DROP FUNCTION IF EXISTS" <+> renderSQL fun <> ";"
1356+
13481357dropOperator
1349− :: (Has sch schemas schema, Has op schema ('Operator oper))
1358+ :: (Has sch schemas schema, KnownSymbol op)
13501359 => QualifiedAlias sch op
13511360 -- ^ name of the user defined operator
1352− -> Definition schemas (Alter sch (Drop op schema) schemas)
1361+ -> Definition schemas (Alter sch (DropSchemum op 'Operator schema) schemas)
13531362dropOperator op = UnsafeDefinition $
13541363 "DROP" <+> "OPERATOR" <+> renderSQL op <> ";"
13551364
1365+dropOperatorIfExists
1366+ :: (Has sch schemas schema, KnownSymbol op)
1367+ => QualifiedAlias sch op
1368+ -- ^ name of the user defined operator
1369+ -> Definition schemas (Alter sch (DropSchemumIfExists op 'Operator schema) schemas)
1370+dropOperatorIfExists op = UnsafeDefinition $
1371+ "DROP OPERATOR IF EXISTS" <+> renderSQL op <> ";"
1372+
13561373newtype FunctionDefinition schemas args ret = UnsafeFunctionDefinition
13571374 { renderFunctionDefinition :: ByteString }
13581375 deriving (Eq,Show,GHC.Generic,NFData)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4−4
@@ -342,11 +342,11 @@ type family CreateOrReplace alias x xs where
342342 CreateOrReplace alias x (alias ::: x ': xs) = alias ::: x ': xs
343343 CreateOrReplace alias x (alias ::: y ': xs) = TypeError
344344 ('Text "CreateOrReplace: expected type "
345− ':<>: 'ShowType y
345+ ':<>: 'ShowType x
346346 ':<>: 'Text " but alias "
347347 ':<>: 'ShowType alias
348348 ':<>: 'Text " has type "
349− ':<>: 'ShowType x)
349+ ':<>: 'ShowType y)
350350 CreateOrReplace alias y (x ': xs) = x ': CreateOrReplace alias y xs
351351
352352-- | @Drop alias xs@ removes the type associated with @alias@ in @xs@
@@ -368,11 +368,11 @@ type family DropSchemum alias sch xs where
368368 DropSchemum alias sch (alias ::: sch x ': xs) = xs
369369 DropSchemum alias sch0 (alias ::: sch1 x ': xs) = TypeError
370370 ('Text "DropSchemum: expected schemum "
371− ':<>: 'ShowType sch1
371+ ':<>: 'ShowType sch0
372372 ':<>: 'Text " but alias "
373373 ':<>: 'ShowType alias
374374 ':<>: 'Text " has schemum "
375− ':<>: 'ShowType sch0)
375+ ':<>: 'ShowType sch1)
376376 DropSchemum alias sch (x ': xs) = x ': DropSchemum alias sch xs
377377
378378type family DropIfExists alias xs where