2017-06-11 23:11:14 +02:00
|
|
|
import SQLite from 'react-native-sqlite-storage';
|
|
|
|
|
|
|
|
class DatabaseDriverReactNative {
|
|
|
|
|
|
|
|
open(options) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
SQLite.openDatabase({ name: options.name }, (db) => {
|
|
|
|
this.db_ = db;
|
|
|
|
resolve();
|
|
|
|
}, (error) => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-24 19:40:03 +02:00
|
|
|
setDebugMode(v) {
|
|
|
|
//SQLite.DEBUG(v);
|
2017-06-11 23:11:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
selectOne(sql, params = null) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.db_.executeSql(sql, params, (r) => {
|
|
|
|
resolve(r.rows.length ? r.rows.item(0) : null);
|
|
|
|
}, (error) => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAll(sql, params = null) {
|
|
|
|
return this.exec(sql, params).then((r) => {
|
|
|
|
let output = []
|
|
|
|
for (let i = 0; i < r.rows.length; i++) {
|
|
|
|
output.push(r.rows.item(i));
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exec(sql, params = null) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.db_.executeSql(sql, params, (r) => {
|
|
|
|
resolve(r);
|
|
|
|
}, (error) => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export { DatabaseDriverReactNative }
|