本文整理汇总了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 ("*** 終了 ***");
// ------------------------------------------------------------