本文整理汇总了TypeScript中sqlite3.Database.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Database.all方法的具体用法?TypeScript Database.all怎么用?TypeScript Database.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlite3.Database
的用法示例。
在下文中一共展示了Database.all方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
var data = await new Promise((rs,rj)=>{
db.all(`select * from things_store where key = '${key}'`, (err, data)=>{
if(err){
rj(err);
return;
}
rs(data);
});
});
示例2: reject
db.serialize(()=>{
db.all(sql, (err, data /*rows*/)=> {
if (err) {
reject(err);
return
}
resolve(data);
})
})
示例3: getMessages
// get messages from the database
function getMessages(cb: (messages: Messages) => void, handle_id=false): void {
let query = handle_id ? 'select text from message where handle_id=?' : 'select text from message where is_from_me=1' ;
let result = [];
if (handle_id) {
db.all(query, handle_id, (err, data) => {
if (!err) {
cb(data);
} else {
console.error(err);
}
});
} else {
db.all(query, (err, data) => {
if (!err) {
cb(data);
} else {
console.error(err);
}
});
}
};
示例4: 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);
}
}
);
});
示例5: Promise
return new Promise((resolve, reject) => {
userid = Util.toId(userid);
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);
});
}
});
});
示例6: Promise
return new Promise((resolve, reject) => {
roomid = Util.toId(roomid);
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);
});
}
});
});
示例7: 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;
}
});