This commit is contained in:
Eitan Chatav 2019-09-16 19:54:55 -07:00
parent 787bbc412e
commit 9282502a7a
2 changed files with 26 additions and 1 deletions

View File

@ -70,11 +70,13 @@ module Squeal.PostgreSQL.Definition
, languageSqlQuery
-- ** Drop
, dropSchema
, dropSchemaIfExists
, dropTable
, dropTableIfExists
, dropView
, dropType
, dropIndex
, dropIndexIfExists
, dropFunction
, dropOperator
-- ** Alter
@ -596,6 +598,14 @@ dropSchema
-> Definition schemas (Drop sch schemas)
dropSchema sch = UnsafeDefinition $ "DROP SCHEMA" <+> renderSQL sch <> ";"
dropSchemaIfExists
:: Has sch schemas schema
=> Alias sch
-- ^ user defined schema
-> Definition schemas (Drop sch schemas)
dropSchemaIfExists sch = UnsafeDefinition $
"DROP SCHEMA IF EXISTS" <+> renderSQL sch <> ";"
-- | `dropTable` removes a table from the schema.
--
-- >>> :{
@ -952,6 +962,13 @@ dropView
-> Definition schemas (Alter sch (Drop vw schema) schemas)
dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderSQL vw <> ";"
dropViewIfExists
:: (Has sch schemas schema, Has vw schema ('View view))
=> QualifiedAlias sch vw -- ^ view to remove
-> Definition schemas (Alter sch (Drop vw schema) schemas)
dropViewIfExists vw = UnsafeDefinition $
"DROP VIEW IF EXISTS" <+> renderSQL vw <> ";"
-- | Enumerated types are created using the `createTypeEnum` command, for example
--
-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition (Public '[]) '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
@ -1325,6 +1342,14 @@ dropIndex
-> Definition schemas (Alter sch (Drop ix schema) schemas)
dropIndex ix = UnsafeDefinition $ "DROP" <+> "INDEX" <+> renderSQL ix <> ";"
dropIndexIfExists
:: (Has sch schemas schema, Has ix schema 'Index)
=> QualifiedAlias sch ix
-- ^ name of the user defined index
-> Definition schemas (Alter sch (DropIfExists ix schema) schemas)
dropIndexIfExists ix = UnsafeDefinition $
"DROP INDEX IF EXISTS" <+> renderSQL ix <> ";"
-- | Lift `PGTyped` to a field
class FieldTyped schemas ty where
fieldtype :: Aliased (TypeExpression schemas) ty

View File

@ -325,7 +325,7 @@ type family Create alias x xs where
Create alias x (alias ::: y ': xs) = TypeError
('Text "Create: alias "
':<>: 'ShowType alias
':<>: 'Text "already in use")
':<>: 'Text "already exists")
Create alias y (x ': xs) = x ': Create alias y xs
type family CreateOrReplace alias x xs where