Skip to content

Instantly share code, notes, and snippets.

@ProfAndreaPollini
Created March 23, 2020 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProfAndreaPollini/1fc5856e4914d707d34c5469c1ca3514 to your computer and use it in GitHub Desktop.
Save ProfAndreaPollini/1fc5856e4914d707d34c5469c1ca3514 to your computer and use it in GitHub Desktop.
accesso a un DB sqlite da node.js
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);
});
});
@ProfAndreaPollini
Copy link
Author

installare la libreria con npm i sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment