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


TypeScript sqlite3.Database类代码示例

本文整理汇总了TypeScript中sqlite3.Database的典型用法代码示例。如果您正苦于以下问题:TypeScript Database类的具体用法?TypeScript Database怎么用?TypeScript Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Database类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: 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

示例3: Promise

 return new Promise((resolve, reject) => {
   let db = new Database(DB_PATH);
   return db.all(
     "SELECT * FROM entries WHERE userid = ? ORDER BY date",
     [userId],
     (err, rows) => {
       if (!rows) {
         reject(err);
       } else {
         if (err) { console.error(err); }
         resolve(rows);
       }
     }
     );
 });
开发者ID:Ethan826,项目名称:diet-tracker,代码行数:15,代码来源:db.ts

示例4: users

   .then(data => {
   db.run(
     "insert into users (username, salt, hashedpwd) values (?, ?, ?)",
     [data.username, data.salt, data.hash], cb // Null on success, single error parameter on success
     );
   db.close();
 });
开发者ID:Ethan826,项目名称:diet-tracker,代码行数:7,代码来源:db.ts

示例5: 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);
    });
  })
开发者ID:kimsk,项目名称:try-typescript,代码行数:9,代码来源:parse-promise.ts

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

示例7: users

 database.all("SELECT * FROM users WHERE user_id=$userid", { $userid: userid }, (err, rows) => {
    if (rows.length < 1) {
       database.run("INSERT INTO users(user_id, lastfm_name) VALUES ($userid, $lastfm)", { $userid: userid, $lastfm: lastfmName }, (err) => {
          if (err) reject(Util.errorMsg(err));
          resolve(rows);
       });
    } else {
       database.run("UPDATE users SET lastfm_name=$lastfm WHERE user_id=$userid", { $lastfm: lastfmName, $userid: userid }, (err) => {
          if (err) reject(Util.errorMsg(err));
          resolve(rows);
       });
    }
 });
开发者ID:Itachi2000,项目名称:PS-Bot,代码行数:13,代码来源:userdao.ts

示例8: rooms

 database.all("SELECT * FROM rooms WHERE room_id=$roomid", { $roomid: roomid }, (err, rows) => {
   if (rows.length < 1) {
     database.run("INSERT INTO rooms(room_id, auto_join) VALUES ($roomid, $status)", { $roomid: roomid, $status: status }, (err) => {
       if (err) reject(Util.errorMsg(err));
       resolve(rows);
     });
   } else {
     database.run("UPDATE rooms SET auto_join=$status WHERE room_id=$roomid", { $status: status, $roomid: roomid }, (err) => {
       if (err) reject(Util.errorMsg(err));
       resolve(rows);
     });
   }
 });
开发者ID:Itachi2000,项目名称:PS-Bot,代码行数:13,代码来源:roomdao.ts

示例9:

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


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