-
Notifications
You must be signed in to change notification settings - Fork 664
TRIGGER
Mathias Wulff edited this page Jul 2, 2023
·
6 revisions
Syntax:
CREATE TRIGGER triggerName (BEFORE|AFTER|INSTEAD OF) (INSERT|DELETE|UPDATE) ON tableName (Statement|Function)
Example A
alasql.fn.verify = function(r) {
if(r.n == 42) return false; // Do not insert on this number
};
alasql('CREATE TRIGGER mytrigger BEFORE INSERT ON mytable verify');
Example B
alasql.fn.onchange = function(r) {
if(r.a == 123) console.log('Observable event!');
};;
alasql('CREATE TABLE one (a INT)');
alasql('CREATE TRIGGER two BEFORE INSERT ON one CALL onchange()');
alasql('INSERT INTO one VALUES (123)'); // This will fire onchange()
Limitations:
- No
INSTEAD OF DELETE
-
BEFORE/AFTER DELETE
can not prevent record from deletion - Triggers do not works for
DELETE FROM
mytable withoutWHEN
clause - Some issues have been reported on indexedDB. Please report any new issues.
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo