Created
March 23, 2020 11:51
-
-
Save ProfAndreaPollini/1fc5856e4914d707d34c5469c1ca3514 to your computer and use it in GitHub Desktop.
accesso a un DB sqlite da node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sqlite3 = require("sqlite3").verbose(); | |
var db = new sqlite3.Database("database.db"); | |
db.serialize(function() { | |
db.run("CREATE TABLE IF NOT EXISTS utenti (nome VARCHAR)"); | |
const stmt = db.prepare("INSERT INTO utenti VALUES (?)"); | |
for (var i = 0; i < 10; i++) { | |
stmt.run("utente " + i); | |
} | |
stmt.finalize(); | |
db.each("SELECT rowid AS id, nome FROM utenti", function(err, row) { | |
console.log(row); | |
console.log(row.id + ": " + row.nome); | |
}); | |
db.all("SELECT rowid, nome FROM utenti", function(err, rows) { | |
console.log(rows); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
installare la libreria con npm i sqlite3