Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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 TriggerEvent
- data Trigger = Trigger {
- triggerTable :: RawSQL ()
- triggerName :: RawSQL ()
- triggerEvents :: Set TriggerEvent
- triggerDeferrable :: Bool
- triggerInitiallyDeferred :: Bool
- triggerWhen :: Maybe (RawSQL ())
- triggerFunction :: RawSQL ()
- 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, RawSQL ())]
- sqlCreateTriggerFunction :: Trigger -> RawSQL ()
- sqlDropTriggerFunction :: Trigger -> RawSQL ()
- triggerFunctionMakeName :: RawSQL () -> RawSQL ()
Triggers
data TriggerEvent Source #
Trigger event name.
Since: 1.15.0.0
TriggerInsert | The |
TriggerUpdate | The |
TriggerUpdateOf [RawSQL ()] | The |
TriggerDelete | The |
Instances
Show TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger showsPrec :: Int -> TriggerEvent -> ShowS # show :: TriggerEvent -> String # showList :: [TriggerEvent] -> ShowS # | |
Eq TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger (==) :: TriggerEvent -> TriggerEvent -> Bool # (/=) :: TriggerEvent -> TriggerEvent -> Bool # | |
Ord TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger compare :: TriggerEvent -> TriggerEvent -> Ordering # (<) :: TriggerEvent -> TriggerEvent -> Bool # (<=) :: TriggerEvent -> TriggerEvent -> Bool # (>) :: TriggerEvent -> TriggerEvent -> Bool # (>=) :: TriggerEvent -> TriggerEvent -> Bool # max :: TriggerEvent -> TriggerEvent -> TriggerEvent # min :: TriggerEvent -> TriggerEvent -> TriggerEvent # |
Trigger.
Since: 1.15.0.0
Trigger | |
|
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