本文整理匯總了TypeScript中sqlite3.Database.each方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Database.each方法的具體用法?TypeScript Database.each怎麽用?TypeScript Database.each使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3.Database
的用法示例。
在下文中一共展示了Database.each方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: VALUES
.then((data) => {
console.log(data.cols);
console.log(data.records);
db.run("INSERT INTO memos VALUES('TEST', 5000)");
db.each("SELECT * FROM memos", (err, row) => {
console.log(row.text);
});
})
示例2: reject
db.serialize(()=>{
try{
db.each(cmd, params, (err, data)=>{
if(err){
reject(err);
return;
}
resolve(data);
})
}catch(e){
reject(e);
}
});
示例3: lorem
db.serialize(() => {
db.run("CREATE TABLE lorem (info TEXT)");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize();
db.each("SELECT rowid AS id, info FROM lorem", (err, row) => {
console.log(row.id + ": " + row.info);
});
});
示例4:
db.serialize(() => {
db.each(
"SELECT channel_id, timestamp, type, nickname, user_id, message FROM chat WHERE channel_id=? AND timestamp>=? ORDER BY id",
param.channelId,
Date.now() - 1000 * 60 * 60 * 24 * 7,
(err: Error, row: any) => {
if (err === null) {
let message: IMessage = {
channelId: row.channel_id,
timestamp: row.timestamp,
type: row.type,
message: row.message,
nickname: row.nickname,
userId: row.user_id,
};
event.sender.send("getChatLogs", JSON.stringify(message));
} else {
console.log(err);
}
}
);
});
示例5: require
import * as _ from 'lodash';
import * as sqlite3 from 'sqlite3';
import * as fs from 'fs';
var parse = require('csv-parse');
var parser = parse({delimiter: ';'}, function(err, data){
console.log(data);
});
fs.createReadStream(__dirname+'/../fs_read.csv').pipe(parser);
var db = new sqlite3.Database('test.db');
db.run("INSERT INTO memos VALUES('TEST', 5000)");
db.each("SELECT * FROM memos", (err, row) => {
console.log(row.text);
});
db.close();
let arr: number[] = [1, 2, 3];
_.forEach(arr, (v) => console.log(v));
console.log('running...');
示例6: require
//
// Feb/09/2016
//
// ------------------------------------------------------------
declare function require(x: string): any;
declare var process:any;
var sqlite3 = require("sqlite3");
// ------------------------------------------------------------
console.log ("*** 開始 ***");
var file_sqlite3: string = process.argv[2];
console.log (file_sqlite3);
var db = new sqlite3.Database (file_sqlite3);
var command: string = "select id,name,population,date_mod from cities";
db.each (command,function (err,row)
{
var str_out:string = row.id + "\t" + row.name + "\t" + row.population;
str_out += "\t" + row.date_mod;
console.log (str_out);
});
db.close ();
console.log ("*** 終了 ***");
// ------------------------------------------------------------