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