I want Sqlite to autopopulate timestamp, but Javascript doesn't allow me to pass only 2 values (like
VALUES (?, ?)
new Date()
db.serialize(function () {
db.run("CREATE TABLE if not exists songs (title TEXT, lyric TEXT, timestamp DATATIME DEFAULT CURRENT_TIMESTAMP)");
var stmt = db.prepare("INSERT INTO songs VALUES (?, ?, ?)");
for (var i = 0; i < 10; i++) {
stmt.run("Title" + i, "Lyric" + i);
}
stmt.finalize();
});
If you want to use the default value for a column then just leave it out of the INSERT:
var stmt = db.prepare("INSERT INTO songs (title, lyric) VALUES (?, ?)");
Two things to note here:
INSERT
statement is always a good idea, hence the (title, lyric)
addition. This way there is no ambiguity as to what the placeholders are referring to.