Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Last active October 8, 2018 12:42
Show Gist options
  • Save jtuttas/7cfe735dd1c2957606eb35c8767168bb to your computer and use it in GitHub Desktop.
Save jtuttas/7cfe735dd1c2957606eb35c8767168bb to your computer and use it in GitHub Desktop.
SQLITE mit Node.js
var sqlite3 = require('sqlite3').verbose();
db = new sqlite3.Database('./users.db');
db.serialize(function () {
db.run("CREATE TABLE IF NOT EXISTS users (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"uuid VARCHAR (80) NOT NULL," +
"email VARCHAR (80) NOT NULL," +
"generated DATETIME," +
"accepted DATETIME" +
");");
});
db.run("INSERT INTO users (uuid,email) VALUES ('abcss','[email protected]');", (err) => {
if (err) {
return console.error(err.message);
}
else {
console.log('inserted');
}
});
db.all("SELECT * FROM users;", (err, rows) => {
if (err) {
return console.error(err.message);
}
else {
rows.forEach(element => {
console.log("found:" + element.id+";"+element.uuid);
});
}
});
{
"name": "sqlitetest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sqlite3": "^4.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment