Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
create and drop procedures
Synopsis
- createProcedure :: (Has sch db schema, KnownSymbol pro, SListI args) => QualifiedAlias sch pro -> NP (TypeExpression db) args -> ProcedureDefinition db args -> Definition db (Alter sch (Create pro ('Procedure args) schema) db)
- createOrReplaceProcedure :: (Has sch db schema, KnownSymbol pro, SListI args) => QualifiedAlias sch pro -> NP (TypeExpression db) args -> ProcedureDefinition db args -> Definition db (Alter sch (CreateOrReplace pro ('Procedure args) schema) db)
- dropProcedure :: (Has sch db schema, KnownSymbol pro) => QualifiedAlias sch pro -> Definition db (Alter sch (DropSchemum pro 'Procedure schema) db)
- dropProcedureIfExists :: (Has sch db schema, KnownSymbol pro) => QualifiedAlias sch pro -> Definition db (Alter sch (DropSchemumIfExists pro 'Procedure schema) db)
- newtype ProcedureDefinition db args = UnsafeProcedureDefinition {}
- languageSqlManipulation :: [Manipulation '[] db args '[]] -> ProcedureDefinition db args
Create
:: (Has sch db schema, KnownSymbol pro, SListI args) | |
=> QualifiedAlias sch pro | procedure alias |
-> NP (TypeExpression db) args | arguments |
-> ProcedureDefinition db args | procedure definition |
-> Definition db (Alter sch (Create pro ('Procedure args) schema) db) |
Create a procedure.
>>>
type Proc = 'Procedure '[ 'NotNull 'PGint4 ]
>>>
type Thing = 'Table ('[] :=> '[ "id" ::: 'NoDef :=> 'NotNull 'PGint4 ])
>>>
:{
let definition :: Definition (Public '["things" ::: Thing ]) (Public '["things" ::: Thing, "proc" ::: Proc]) definition = createProcedure #proc (one int4) . languageSqlManipulation $ [deleteFrom_ #things (#id .== param @1)] in printSQL definition :} CREATE PROCEDURE "proc" (int4) language sql as $$ DELETE FROM "things" AS "things" WHERE ("id" = ($1 :: int4)); $$;
createOrReplaceProcedure Source #
:: (Has sch db schema, KnownSymbol pro, SListI args) | |
=> QualifiedAlias sch pro | procedure alias |
-> NP (TypeExpression db) args | arguments |
-> ProcedureDefinition db args | procedure definition |
-> Definition db (Alter sch (CreateOrReplace pro ('Procedure args) schema) db) |
Create or replace a procedure. It is not possible to change the name or argument types of a procedure this way.
>>>
type Proc = 'Procedure '[ 'NotNull 'PGint4 ]
>>>
type Thing = 'Table ('[] :=> '[ "id" ::: 'NoDef :=> 'NotNull 'PGint4 ])
>>>
:{
let definition :: Definition (Public '["things" ::: Thing ]) (Public '["things" ::: Thing, "proc" ::: Proc]) definition = createOrReplaceProcedure #proc (one int4) . languageSqlManipulation $ [deleteFrom_ #things (#id .== param @1)] in printSQL definition :} CREATE OR REPLACE PROCEDURE "proc" (int4) language sql as $$ DELETE FROM "things" AS "things" WHERE ("id" = ($1 :: int4)); $$;
Drop
:: (Has sch db schema, KnownSymbol pro) | |
=> QualifiedAlias sch pro | procedure alias |
-> Definition db (Alter sch (DropSchemum pro 'Procedure schema) db) |
Drop a procedure.
>>>
type Proc = 'Procedure '[ 'Null 'PGint4, 'Null 'PGint4]
>>>
:{
let definition :: Definition (Public '["proc" ::: Proc]) (Public '[]) definition = dropProcedure #proc in printSQL definition :} DROP PROCEDURE "proc";
dropProcedureIfExists Source #
:: (Has sch db schema, KnownSymbol pro) | |
=> QualifiedAlias sch pro | procedure alias |
-> Definition db (Alter sch (DropSchemumIfExists pro 'Procedure schema) db) |
Drop a procedure.
>>>
type Proc = 'Procedure '[ 'Null 'PGint4, 'Null 'PGint4 ]
>>>
:{
let definition :: Definition (Public '[]) (Public '[]) definition = dropProcedureIfExists #proc in printSQL definition :} DROP PROCEDURE IF EXISTS "proc";
Procedure Definition
newtype ProcedureDefinition db args Source #
Body of a user defined procedure
Instances
languageSqlManipulation Source #
:: [Manipulation '[] db args '[]] | procedure body |
-> ProcedureDefinition db args |
Use a parameterized Manipulation
as a procedure body