download the sqlite3 module for Node JS
npm install sqlite3
Lets connect Node to MySQL
sqlite3 module provide good set of library to get connection to SQLite
include sqlite3module
var sqlite3 = require('sqlite3')
Database is used to construct the connection
var db = new sqlite3.Database(file);
where file is var file="D:/software/sqllite/example.sqlite";
it can be any SQLite file with accessible path
all function return result set for SQLite
db.all("SELECT id, name FROM employee", function(err, employee){
if(err !== null){
console.log(err);
}
else{
console.log(employee);
}
});
it give all employee list in array format
lets use dynamic value
var id ='12\n1';
db.all("SELECT id, name FROM employee where id=?",(id), function(err, employee){
if(err !== null){
console.log(err);
}
else{
console.log(employee);
}
});
lets use the prepare statement
//delete query with prepare statement
var statement = db.prepare("DELETE FROM employee WHERE id = ?", (id));
statement.run();
statement.finalize();
Github