当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Database.serialize方法代码示例

本文整理汇总了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);
				}
			}
			);
	});
});
开发者ID:data9824,项目名称:SavannaTalk,代码行数:25,代码来源:main.ts

示例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);
     });
 });
开发者ID:planningalerts-scrapers,项目名称:city_of_charles_sturt,代码行数:7,代码来源:scraper.ts

示例3: Promise

 return new Promise((resolve, reject)=> {
     db.serialize(()=>{
         db.run(sql, e=> {
             if (_.isError(e)) {
                 reject(e);
                 return;
             }
             resolve(true)
         })
     })
 });
开发者ID:D10221,项目名称:xstore,代码行数:11,代码来源:sqliteAsync.ts

示例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();
   }
 }
开发者ID:Ethan826,项目名称:diet-tracker,代码行数:53,代码来源:db.ts

示例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);
		}
	});
开发者ID:data9824,项目名称:SavannaTalk,代码行数:49,代码来源:main.ts

示例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();
开发者ID:danelkhen,项目名称:desktopbrowser,代码行数:19,代码来源:testsqlite.ts


注:本文中的sqlite3.Database.serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。