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.

Revisions

  1. nmay231 created this gist May 6, 2020.
    12 changes: 12 additions & 0 deletions build_schema.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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");
    5 changes: 5 additions & 0 deletions failToUpdateDB.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    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)
    14 changes: 14 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    {
    "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"
    }
    }