hpqtypes-extras-1.16.4.4: Extra utilities for hpqtypes library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.PostgreSQL.PQTypes.Model.Trigger

Description

Trigger name must be unique among triggers of same table. Only CONSTRAINT triggers are supported. They can only be run AFTER an event. The associated functions are always created with no arguments and always RETURN TRIGGER.

For details, see https://www.postgresql.org/docs/11/sql-createtrigger.html.

Synopsis

Triggers

data TriggerEvent Source #

Trigger event name.

Since: 1.15.0.0

Constructors

TriggerInsert

The INSERT event.

TriggerUpdate

The UPDATE event.

TriggerUpdateOf [RawSQL ()]

The UPDATE OF column1 [, column2 ...] event.

TriggerDelete

The DELETE event.

data Trigger Source #

Trigger.

Since: 1.15.0.0

Constructors

Trigger 

Fields

Instances

Instances details
Show Trigger Source # 
Instance details

Defined in Database.PostgreSQL.PQTypes.Model.Trigger

Eq Trigger Source # 
Instance details

Defined in Database.PostgreSQL.PQTypes.Model.Trigger

Methods

(==) :: Trigger -> Trigger -> Bool #

(/=) :: Trigger -> Trigger -> Bool #

triggerMakeName :: RawSQL () -> RawSQL () -> RawSQL () Source #

Make a trigger name that can be used in SQL.

Given a base name and tableName, return a new name that will be used as the actual name of the trigger in an SQL query. The returned name is in the format trg__<tableName>__<name>.

Since: 1.15.0

triggerBaseName :: RawSQL () -> RawSQL () -> RawSQL () Source #

Return the trigger's base name.

Given the trigger's actual name and tableName, return the base name of the trigger. This is basically the reverse of what triggerMakeName does.

Since: 1.15.0

sqlCreateTrigger :: Trigger -> RawSQL () Source #

Build an SQL statement that creates a trigger.

Only supports CONSTRAINT triggers which can only run AFTER.

Since: 1.15.0

sqlDropTrigger :: Trigger -> RawSQL () Source #

Build an SQL statement that drops a trigger.

Since: 1.15.0

createTrigger :: MonadDB m => Trigger -> m () Source #

Create the trigger in the database.

First, create the trigger's associated function, then create the trigger itself.

Since: 1.15.0

dropTrigger :: MonadDB m => Trigger -> m () Source #

Drop the trigger from the database.

Since: 1.15.0

getDBTriggers :: forall m. MonadDB m => RawSQL () -> m [(Trigger, RawSQL ())] Source #

Get all noninternal triggers from the database.

Run a query that returns all triggers associated with the given table and marked as tgisinternal = false. The second item in the returned tuple is the trigger's function name.

Note that, in the background, to get the trigger's WHEN clause and the source code of the attached function, the entire query that had created the trigger is received using pg_get_triggerdef(t.oid, true)::text and then parsed. The result of that call will be decompiled and normalized, which means that it's likely not what the user had originally typed.

Since: 1.15.0

Trigger functions

sqlCreateTriggerFunction :: Trigger -> RawSQL () Source #

Build an SQL statement for creating a trigger function.

Since we only support CONSTRAINT triggers, the function will always RETURN TRIGGER and will have no parameters.

Since: 1.15.0.0

sqlDropTriggerFunction :: Trigger -> RawSQL () Source #

Build an SQL statement for dropping a trigger function.

Since: 1.15.0.0

triggerFunctionMakeName :: RawSQL () -> RawSQL () Source #

Make a trigger function name that can be used in SQL.

Given a base name, return a new name that will be used as the actual name of the trigger function in an SQL query. The returned name is in the format trgfun__<name>.

Since: 1.16.0.0