本文整理匯總了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;
}
});