node-sqlite3-api-Induction Summary

Source: Internet
Author: User
Tags stmt

Sqlite3-api-list:
Api
1. New Sqlite3. Database (Filename,[mode],[callback])
Returning database objects and automatically opening and connecting to the database
It does not have a way to open the database independently
2. Sqlite3.verbose ()
The execution mode of the integrated database is so easy to debug that it does not have a reset method.
3. Database#close ([callback])
Close and Release database objects
4. Database#run (Sql,param,...],[callback])
Runs the SQL statement of the specified argument, calls the callback function after completion, does not return any data, has a parameter in the callback function, the SQL statement executes successfully, the value of the argument is null, and vice versa is an Error object, which returns the operand of the database. In this callback function, this contains the LastID (inserted ID) and change (the number of rows affected by the operation, if the execution of the SQL statement fails, then the value of the difference is always 0);

5. Database#get (Sql,[param,...],[callback])
Runs the SQL statement for the specified parameter and calls the callback function after completion. If the execution succeeds, the first parameter in the callback function is null, the second parameter is the first row of data in the result set, and vice versa, there is only one parameter in the callback function, and only the argument is an incorrect object.

6. Database#all (Sql,[param,...],[callback])
Runs the SQL statement for the specified parameter and calls the callback function after completion. If the execution succeeds, the first parameter in the callback function is null, the second parameter is the result set of the query, and vice versa, there is only one argument, and the value of the parameter is an incorrect object.

7. Database#prepare (Sql,[param,...],[callback])

Pre-executes the SQL statement that binds the specified arguments, returns a statement object, and, if successful, the first parameter of the callback function is null, and vice versa is an incorrect object.

Examples are as follows:

1Dbfactory.fn = Dbfactory.prototype = {2Fetchall:function(SQL, callback) {3             varSelf = This;4             vararr = [];5Self._db.serialize (function () {6Self._db.all (SQL,function(err, rows) {7Rows.foreach (function(row) {8 Arr.push (row);9                     });TenArr.length > 0? CallbackNULL, arr): Callback (-1); One                 }); A  -             }); -             returnarr; the         }, -Fetchrow:function(SQL, callback) { -             return  This. fetchall (sql + "Limit 1", callback); -         }, +Savefunction(sql,callback) { -             varself= This; +             //Self._db.run (Sql,function () { ASelf._db.run (SQL,function(){ atConsole.log ( This); - console.log (arguments); -             }); -         }, -         Delete:function(SQL) { -              This. _db.run (SQL); in         }, -Updatefunction(SQL, callback) { to  +         }, -Getfunction(sql,callback) { the              This. _db.get (SQL,function(Err,row) {//err->true *Console.log ( This); $ console.log (arguments);Panax Notoginseng                 if(err) { -                    Throwerr; the                 } +             }); A},run:function(){ the             varself= This; +Self._db.serialize (function() { -Console.log ("Prepare"); $                 varstmt = Self._db.prepare ("INSERT into T1 values (null,?)"); $  -                  for(vari = 0; I < 10; i++) { -Stmt.run ("Ipsum" +i); the                 } - stmt.finalize ();WuyiSelf._db.each ("SELECT * from T1",function(err, row) { the console.log (row); -                 }); WuConsole.log ("Init"); -             }); About  $         } -};
View Code

Summarized on December 25, 2014 11:26:07
EDIT BYN Niccky

node-sqlite3-api-Induction Summary

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.