| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Database.PostgreSQL.PQTypes.Model.Trigger
Description
Trigger name must be unique among triggers of the same table.
For details, see https://www.postgresql.org/docs/current/sql-createtrigger.html.
Synopsis
- data TriggerKind
- data TriggerActionTime
- data TriggerEvent
- data Trigger = Trigger {
- triggerTable :: RawSQL ()
- triggerName :: RawSQL ()
- triggerKind :: TriggerKind
- triggerEvents :: Set TriggerEvent
- 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 ()
- data ConstraintAttributes
Triggers
data TriggerKind Source #
Trigger kind.
Since: 1.17.0.0
Constructors
| TriggerRegular TriggerActionTime | Create a regular trigger: |
| TriggerConstraint ConstraintAttributes | Create a constraint trigger: |
Instances
| Show TriggerKind Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> TriggerKind -> ShowS # show :: TriggerKind -> String # showList :: [TriggerKind] -> ShowS # | |
| Eq TriggerKind Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger | |
data TriggerActionTime Source #
Timing for a regular trigger.
Since: 1.17.0.0
Instances
| Show TriggerActionTime Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> TriggerActionTime -> ShowS # show :: TriggerActionTime -> String # showList :: [TriggerActionTime] -> ShowS # | |
| Eq TriggerActionTime Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods (==) :: TriggerActionTime -> TriggerActionTime -> Bool # (/=) :: TriggerActionTime -> TriggerActionTime -> Bool # | |
data TriggerEvent Source #
Trigger event name.
Since: 1.15.0.0
Constructors
| TriggerInsert | The |
| TriggerUpdate | The |
| TriggerUpdateOf [RawSQL ()] | The |
| TriggerDelete | The |
Instances
| Show TriggerEvent Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> TriggerEvent -> ShowS # show :: TriggerEvent -> String # showList :: [TriggerEvent] -> ShowS # | |
| 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 # | |
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.
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
Constraints
data ConstraintAttributes Source #
Possible combinations of constraint attributes.
Since: 1.17.0.0
Constructors
| NotDeferrable | The |
| Deferrable | The |
| DeferrableInitiallyDeferred | The |
Instances
| Show ConstraintAttributes Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods showsPrec :: Int -> ConstraintAttributes -> ShowS # show :: ConstraintAttributes -> String # showList :: [ConstraintAttributes] -> ShowS # | |
| Eq ConstraintAttributes Source # | |
Defined in Database.PostgreSQL.PQTypes.Model.Trigger Methods (==) :: ConstraintAttributes -> ConstraintAttributes -> Bool # (/=) :: ConstraintAttributes -> ConstraintAttributes -> Bool # | |