Open Database
var db = new Sqlite3. Database (' xx.db ');
Close the database
Db.close ();
Db.run (' xx '); The run function of a database object can execute any SQL statement that is not typically used to execute a query
Create alter and the like
Increase:
var stmt = Db.prepare ("INSERT OR REPLACE into note (cdate, content) VALUES (?,?)");
Stmt.run (Data.cdate, data.content);
Stmt.finalize ();
By deleting:
Db.prepare ("DELETE from note where CDate =?");
Stmt.run (data.cdate);
Stmt.finalize ();
Change:
var stmt = Db.prepare ("UPDATE note set content=?") where CDate =? ");
Stmt.run (Data.content, data.cdate);
Stmt.finalize ();
Check:
Db.each ("Select rowID as ID, thing from Stuff", function (err, row) {
Console.log (row.id + ":" + row.thing);
});
});
Or
Db.all ("Select xxx", function (err, res) {});
Use
1. Introduction of Sqlite3 Library
var sqlite3 = require (' sqlite3 ');
or var sqlite3 = require ("Sqlite3"). verbose ();
var db = new Sqlite3. Database (file);
Db.serialize (function () {
Do stuff ...
Db.run ("CREATE TABLE Stuff (thing TEXT)");
var stmt = Db.prepare ("INSERT into Stuff VALUES (?)");
for (var i = 0;i<xx;i++) {
Stmt.run (' xx ');
}
Stmt.finalize ();
});
Db.close ();
Nodejs and SQLite
Http://blog.modulus.io/nodejs-and-sqlite
Http://book.51cto.com/art/201504/473574.htm
https://www.sqlite.org/
Nodejs and SQLite