本文整理汇总了TypeScript中sqlite3.Database.run方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Database.run方法的具体用法?TypeScript Database.run怎么用?TypeScript Database.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlite3.Database
的用法示例。
在下文中一共展示了Database.run方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
});
}
});
示例2: 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);
});
}
});
示例3: 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();
});
示例4: _rollbackTransaction
private _rollbackTransaction(
db: Database,
error: Error,
errorAction: (error: Error) => void) {
db.run("ROLLBACK", err => {
errorAction(error);
});
}
示例5: reject
db.serialize(()=>{
db.run(sql, e=> {
if (_.isError(e)) {
reject(e);
return;
}
resolve(true)
})
})
示例6: 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);
});
})
示例7: chat
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);
}
}
);
});
示例8: _commitTransaction
private _commitTransaction(
db: Database,
action: () => void,
errorAction: (error: Error) => void) {
db.run("COMMIT", err => {
if (err) {
errorAction(err);
} else {
action();
}
});
}
示例9: 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);
});
});
示例10: Promise
return new Promise((resolve, reject) => {
switch (queryType) {
case QueryType.SELECT:
this.db.all(query, params, (err, rows) => {
if (err) {
reject(err);
} else {
resolve(rows);
}
});
break;
case QueryType.INSERT:
this.db.run(query, params, function (err) {
// Do not use arrow function so we can access 'this'
// See https://github.com/mapbox/node-sqlite3/wiki/API#databaserunsql-param--callback
if (err) {
reject(err);
} else {
resolve(this.lastID);
}
});
break;
case QueryType.UPDATE:
case QueryType.DELETE:
this.db.run(query, params, function (err) {
// Do not use arrow function so we can access 'this'
// See https://github.com/mapbox/node-sqlite3/wiki/API#databaserunsql-param--callback
if (err) {
reject(err);
} else {
resolve(this.changes);
}
});
break;
}
});