squeal-postgresql-0.9.1.3: Squeal PostgreSQL Library
Copyright(c) Eitan Chatav 2019
Maintainereitan@morphism.tech
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Squeal.PostgreSQL.Definition.Procedure

Description

create and drop procedures

Synopsis

Create

createProcedure Source #

Arguments

:: (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 #

Arguments

:: (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

dropProcedure Source #

Arguments

:: (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 #

Arguments

:: (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

Instances details
Generic (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

Associated Types

type Rep (ProcedureDefinition db args) :: Type -> Type #

Methods

from :: ProcedureDefinition db args -> Rep (ProcedureDefinition db args) x #

to :: Rep (ProcedureDefinition db args) x -> ProcedureDefinition db args #

Show (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

NFData (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

Methods

rnf :: ProcedureDefinition db args -> () #

Eq (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

Methods

(==) :: ProcedureDefinition db args -> ProcedureDefinition db args -> Bool #

(/=) :: ProcedureDefinition db args -> ProcedureDefinition db args -> Bool #

RenderSQL (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

type Rep (ProcedureDefinition db args) Source # 
Instance details

Defined in Squeal.PostgreSQL.Definition.Procedure

type Rep (ProcedureDefinition db args) = D1 ('MetaData "ProcedureDefinition" "Squeal.PostgreSQL.Definition.Procedure" "squeal-postgresql-0.9.1.3-FfCgbPNg57H53ZAGizr3Nu" 'True) (C1 ('MetaCons "UnsafeProcedureDefinition" 'PrefixI 'True) (S1 ('MetaSel ('Just "renderProcedureDefinition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

languageSqlManipulation Source #

Arguments

:: [Manipulation '[] db args '[]]

procedure body

-> ProcedureDefinition db args 

Use a parameterized Manipulation as a procedure body