node.js的sqlite3模块api翻译

Database#each(sql, [param, ...], [callback], [complete])

Runs the SQL query with the specified parameters and calls the callback with for each result row. The function returns the Database object to allow for function chaining. The parameters are the same as the Database#run function, with the following differences:

The signature of the callback is function(err, row) {}. If the result set succeeds but is empty, the callback is never called. In all other cases, the callback is called once for every retrieved row. The order of calls correspond exactly to the order of rows in the result set.

After all row callbacks were called, the completion callback will be called if present. The first argument is an error object, and the second argument is the number of retrieved rows. If you specify only one function, it will be treated as row callback, if you specify two, the first (== second to last) function will be the row callback, the last function will be the completion callback.

If you know that a query only returns a very limited number of rows, it might be more convenient to use Database#all to retrieve all rows at once.

There is currently no way to abort execution.

用指定的参数运行sql查询语句,并对每一行结果执行回调函数callback。此函数返回的是database类型的对象以便于进行链式调用。参数基本上和Database#run相同,除了以下区别:

回调函数的(签名?)类型是function(err, row) {}但是如果sql查询语句的执行结果是成功的,但是没有返回值(只是update,delete或者create),那么回调函数永远不会被调用。但是在其它情况下,会对每一行返回值调用回调函数。执行回调函数的顺序和查询语句返回的结果行的顺序相同。

如果定义了complete回调函数,那么它会在所有返回行的callback函数执行完之后被调用。它的类型同样是function(err, row) {},第一个参数是一个err对象,第二个是返回值的总行数。如果你只定义了一个回调函数,那么它将被视为行回调函数callback.如果定义了两个,第一个是行回调函数,第二个是最终回调函数。

如果你确定一个查询只会返回很少的几行数据,可能使用Database#all函数来直接获取所有的查询结果更加方便。这样明显就没有什么可能会阻止查询的执行了。

吐槽:然而还是没有告诉我这个是同步还是异步执行的。。。

原文地址:https://www.cnblogs.com/lswit/p/5050717.html