I want Sqlite to autopopulate timestamp, but Javascript doesn't allow me to pass only 2 values (like VALUES (?, ?)) and let Sqlite handle the 3rd value for the timestamp. I know I can provide the 3rd value with new Date() but this is not the preferred way.
If I run the below code as is, the timestamp column is all null.
What is the right way to do this?
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();
});