本文整理匯總了TypeScript中sqlite3.Database.serialize方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Database.serialize方法的具體用法?TypeScript Database.serialize怎麽用?TypeScript Database.serialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3.Database
的用法示例。
在下文中一共展示了Database.serialize方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
ipcMain.on("getChatLogs", (event: IPCMainEvent, arg: string) => {
let param: IGetChatLogsParam = JSON.parse(arg);
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);
}
}
);
});
});
示例2: Promise
return new Promise((resolve, reject) => {
let database = new sqlite3.Database("data.sqlite");
database.serialize(() => {
database.run("create table if not exists [data] ([council_reference] text primary key, [description] text, [on_notice_to] text, [address] text, [info_url] text, [comment_url] text, [date_scraped] text)");
resolve(database);
});
});
示例3: Promise
return new Promise((resolve, reject)=> {
db.serialize(()=>{
db.run(sql, e=> {
if (_.isError(e)) {
reject(e);
return;
}
resolve(true)
})
})
});
示例4: setupDatabase
/**
* Caution: resets database.
*/
static setupDatabase() {
try {
fs.unlinkSync(DB_PATH);
} catch (err) { }
let db = new Database(DB_PATH);
try {
db.serialize(() => {
db.run(`
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
username TEXT NOT NULL UNIQUE,
salt TEXT NOT NULL,
hashedpwd TEXT NOT NULL,
admin INTEGER NOT NULL DEFAULT 0
);
`);
db.run(`
CREATE TABLE entries (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
date TEXT NOT NULL,
hungerscore INTEGER NOT NULL,
hungertext TEXT,
cravingscore INTEGER NOT NULL,
cravingtext TEXT,
satietyscore INTEGER NOT NULL,
satietytext TEXT,
energyscore INTEGER NOT NULL,
energytext TEXT,
wellbeingscore INTEGER NOT NULL,
wellbeingtext TEXT,
carbsscore INTEGER NOT NULL,
carbstext TEXT,
stressambool INTEGER NOT NULL,
stresspmbool INTEGER NOT NULL,
walksbool INTEGER NOT NULL,
movementbool INTEGER NOT NULL,
movementtext TEXT,
bedtimebool INTEGER NOT NULL,
bedtimetext TEXT,
userid INTEGER NOT NULL,
FOREIGN KEY(userid) REFERENCES user(id)
);
`);
});
}
catch (err) { console.error(err); }
finally {
db.close();
}
}
示例5: chat
messages.forEach((message: IMessage) => {
if (channelLockFileDescriptor !== undefined) {
db.serialize(() => {
db.run(
"INSERT INTO chat (channel_id, timestamp, type, nickname, user_id, message) VALUES(?, ?, ?, ?, ?, ?)",
message.channelId, message.timestamp, message.type, message.nickname, message.userId, message.message,
(err: Error) => {
if (err !== null) {
mainWindow.webContents.send("error", "チャットを記録できません。:" + err.name + " " + err.message);
}
}
);
});
}
if (!config.readChat) {
return;
}
if ((!config.readMessage) && message.type === MESSAGE_TYPE_MESSAGE) {
return;
}
if ((!config.readBalloon) && message.type === MESSAGE_TYPE_BALLOON) {
return;
}
if ((!config.readAnnounce) && message.type === MESSAGE_TYPE_ANNOUNCE) {
return;
}
if ((!config.readViewer) && message.type === MESSAGE_TYPE_VIEWER) {
return;
}
if ((!config.readLikes) && message.type === MESSAGE_TYPE_LIKES) {
return;
}
let text: string = message.message;
if (message.type === MESSAGE_TYPE_LIKES) {
text = "Eねされました。";
} else {
text = text.replace(/https?:\/\/[\-_\.!~*'\(\)a-zA-Z0-9;/\?:@&=\+\$,%#]+/g, "(URL省略)");
}
if (config.readNickname ||
message.type === MESSAGE_TYPE_VIEWER ||
message.type === MESSAGE_TYPE_BALLOON) {
text = text.replace(/。$/, "") + " " + message.nickname;
}
if (process.platform === "darwin") {
speakMac(text);
} else {
speakWin(text);
}
});
示例6: verbose
import { verbose, Database } from 'sqlite3';
verbose();
let db = new Database(':memory:');
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);
});
});
db.close();