Last active
October 8, 2018 12:42
-
-
Save jtuttas/7cfe735dd1c2957606eb35c8767168bb to your computer and use it in GitHub Desktop.
SQLITE mit 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(); | |
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); | |
}); | |
} | |
}); |
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
{ | |
"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