Description
Triggers enable users to define event-based actions. For example, if a table is updated, then run a query to update predictions.Currently, you can create triggers on the following data sources:
- MongoDB (available for MongoDB Atlas Database),
- Slack,
- Solace,
- PostgreSQL (requires write access).
Syntax
Here is the syntax for creating a trigger:sql_code provided in the statement will be executed.
You can create a trigger either on a table…
Example
Firstly, connect Slack to MindsDB following this instruction and connect the Slack app to a channel.- We select the question from the Slack connection and the answer generated by the model.
- We join the model with the
messagestable. - In the
WHEREclause:- We provide the channel name where the app/bot is integrated.
- We exclude the messages sent by the app/bot. You can find the user ID of the app/bot by querying the
mindsdb_slack.userstable. - We use the
LASTkeyword to ensure that the model generates answers only to the newly sent messages.
- We create a trigger named
slack_trigger. - The trigger is created on the
mindsdb_slack.messagestable. Therefore, every time when data is added or updated, the trigger will execute its code. - We provide the code to be executed by the trigger every time the triggering event takes place.
- We insert an answer generated by the model into the
messagestable. - The
TABLE_DELTAstands for the table on which the trigger has been created. - We exclude the messages sent by the app/bot. You can find the user ID of the app/bot by querying the
mindsdb_slack.userstable.
- We insert an answer generated by the model into the