Skip to content

Instantly share code, notes, and snippets.

@nmay231
Created May 6, 2020 00:47
Show Gist options
  • Save nmay231/af28b35d412a365c1d86fb6c7e33c60f to your computer and use it in GitHub Desktop.
Save nmay231/af28b35d412a365c1d86fb6c7e33c60f to your computer and use it in GitHub Desktop.
better-sqlite3 trigger bug
CREATE TABLE Test (
id integer primary key autoincrement,
data text not null,
_last_updated datetime default current_timestamp
);
CREATE TRIGGER update_test_timestamp
AFTER UPDATE ON Test BEGIN
UPDATE Test SET _last_updated = datetime("now") WHERE id = new.id;
END;
INSERT INTO Test(data) VALUES("blah blah blah");
const connect = require('better-sqlite3')
const db = connect('test.db', { fileMustExist: true })
db.prepare('UPDATE Test SET data=? WHERE id=?').run('blah blah 3.0', 1)
{
"name": "sqlite-bug",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"better-sqlite3": "^7.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment