| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.PostgreSQL.PQTypes.Model.Trigger
Contents
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
- data TriggerFunction = TriggerFunction {}
- sqlCreateTriggerFunction :: TriggerFunction -> RawSQL ()
- sqlDropTriggerFunction :: TriggerFunction -> RawSQL ()
- data TriggerEvent
- data Trigger = Trigger {
- triggerTable :: RawSQL ()
- triggerName :: RawSQL ()
- triggerEvents :: Set TriggerEvent
- triggerDeferrable :: Bool
- triggerInitiallyDeferred :: Bool
- triggerWhen :: Maybe (RawSQL ())
- triggerFunction :: TriggerFunction
- triggerMakeName :: RawSQL () -> RawSQL () -> RawSQL ()
- triggerBaseName :: RawSQL () -> RawSQL () -> RawSQL ()
- sqlCreateTrigger :: Trigger -> RawSQL ()
- sqlDropTrigger :: Trigger -> RawSQL ()
- createTrigger :: MonadDB m => Trigger -> m ()
- dropTrigger :: MonadDB m => Trigger -> m ()
- getDBTriggers :: forall m. MonadDB m => RawSQL () -> m [Trigger]
Trigger functions
data TriggerFunction Source #
Function associated with a trigger.
Since: 1.15.0.0
Constructors
| TriggerFunction | |
Instances
| Eq TriggerFunction Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods (==) :: TriggerFunction -> TriggerFunction -> Bool # (/=) :: TriggerFunction -> TriggerFunction -> Bool # | |
| Show TriggerFunction Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> TriggerFunction -> ShowS # show :: TriggerFunction -> String # showList :: [TriggerFunction] -> ShowS # | |
sqlCreateTriggerFunction :: TriggerFunction -> 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 :: TriggerFunction -> RawSQL () Source #
Build an SQL statement for dropping a trigger function.
Since: 1.15.0.0
Triggers
data TriggerEvent Source #
Trigger event name.
Since: 1.15.0.0
Constructors
| TriggerInsert | The |
| TriggerUpdate | The |
| TriggerUpdateOf [RawSQL ()] | The |
| TriggerDelete | The |
Instances
| Eq TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger | |
| Ord TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods compare :: TriggerEvent -> TriggerEvent -> Ordering # (<) :: TriggerEvent -> TriggerEvent -> Bool # (<=) :: TriggerEvent -> TriggerEvent -> Bool # (>) :: TriggerEvent -> TriggerEvent -> Bool # (>=) :: TriggerEvent -> TriggerEvent -> Bool # max :: TriggerEvent -> TriggerEvent -> TriggerEvent # min :: TriggerEvent -> TriggerEvent -> TriggerEvent # | |
| Show TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> TriggerEvent -> ShowS # show :: TriggerEvent -> String # showList :: [TriggerEvent] -> ShowS # | |
Trigger.
Since: 1.15.0.0
Constructors
| Trigger | |
Fields
| |
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] 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.
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