Nodejs and SQLite

Source: Internet
Author: User
Tags sqlite stmt

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.