Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite-nodejs3: How do I notify nodejs when sqlite trigger has been triggered?

Tags:

node.js

sqlite

Here is what I need:

  1. Nodejs creates a trigger in sqlite db (using node-sqlite3 module)
  2. Trigger, well, gets triggered.
  3. Nodejs process gets notified of that.

Here is what I am exloring:

  1. Is it possible to supply a js callback when creating a trigger?
  2. If not, is there an event in nodejs that I can listen to?
  3. If not, can I use RAISE() in sqlite and catch it in nodejs?
  4. What other possibilities are there? Perhaps have sqlite write to a socket?

Any wise man out there to nudge me in a right direction?

like image 323
Lex Avatar asked Jun 21 '13 00:06

Lex


People also ask

Does SQLite support triggers?

SQLite trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a particular database table occurs or whenever an UPDATE occurs on one or more specified columns of a table. At this time, SQLite supports only FOR EACH ROW triggers, not FOR EACH STATEMENT triggers.

How many types of triggers are there in SQLite?

Action for the trigger, it is the sql statement. There is two SQLite extension to triggers 'OLD' and 'NEW'.


1 Answers

You can listen for the 'trace' event emitted from the sqlite module. There is currently no way to intercept or stop queries in the module, so the most you can do is listen for this event which is emitted immediately when a query is executed and create your logic from there.

https://github.com/mapbox/node-sqlite3/wiki/Debugging

like image 91
Adam Kerik Avatar answered Nov 15 '22 06:11

Adam Kerik