1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/lib/database-driver-node.js

63 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-06-11 23:11:14 +02:00
const sqlite3 = require('sqlite3').verbose();
const Promise = require('promise');
class DatabaseDriverNode {
open(options) {
return new Promise((resolve, reject) => {
this.db_ = new sqlite3.Database(options.name, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
}
2017-06-24 19:40:03 +02:00
setDebugMode(v) {
2017-06-11 23:11:14 +02:00
// ??
}
selectOne(sql, params = null) {
if (!params) params = {};
return new Promise((resolve, reject) => {
this.db_.get(sql, params, (error, row) => {
if (error) {
reject(error);
return;
}
resolve(row);
});
});
}
selectAll(sql, params = null) {
if (!params) params = {};
return new Promise((resolve, reject) => {
this.db_.all(sql, params, (error, row) => {
if (error) {
reject(error);
return;
}
resolve(row);
});
});
}
exec(sql, params = null) {
if (!params) params = {};
return new Promise((resolve, reject) => {
this.db_.run(sql, params, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
}
}
export { DatabaseDriverNode };