Triggers
An example of adding triggers to my ORM system
Triggers in databases allow automatic execution of specific actions when certain events occur, such as inserting, updating, or deleting records. In my ORM system, triggers can be created using the @Trigger
decorator.
Example 1: Trigger for the tasks
Table
In this example, the trigger fires before updating a record in the tasks
table. The trigger executes a function that checks or modifies data before the update.
Example 2: Trigger for the users
Table
In this example, the trigger after_delete_user
is set to fire after a record is deleted from the users
table. This trigger uses a class with methods that return functions to handle the post-deletion logic.
In this example, the after_delete_user
trigger executes the logUserDeletion
method from the Functions
class, which logs an entry in the audit trail after a user is deleted from the users
table.
Triggers are a powerful tool for automating certain processes in the database, enhancing control and security when working with data. My ORM system provides flexibility in creating and managing triggers, allowing both direct function definitions in text form and using methods from separate classes for a more structured approach.
Last updated