In this blog, I’m explaining record insert and retrieve using sqlite database in nodejs.
1. DataBaseConnection.js file
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('databases/users');
db.serialize(function () {
db.run("CREATE TABLE NodeJs (Name TEXT,EmailID TEXT,City TEXT)");
var stmt = db.prepare("INSERT INTO NodeJs VALUES (?,?,?)");
stmt.run("Kamlakar Singh","kamlakarsingh4@gmail.com","Allahabad");
stmt.finalize();
db.each("SELECT rowid AS id, Name,EmailID,City FROM NodeJs", function (err, row) {
console.log(row.id + ": " + row.Name+" : "+row.EmailID+" : "+row.City);
});
});
db.close();
2. Open command prompt and go to your file location your project.
3. Install sqlite3 like this.
Npm install sqlite3.
4. Execute your file like this
5. Record insert and retrieve successfully .
in my next post i'll explain about Javascript framework and library
Leave Comment