當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。