blob: d6e808638e5b559bd501361a49ac1124428487a1 [file]
'use strict';
const customOpen = require('../node-websql/lib/index');
var cachedDatabases = new Map();
// openDatabase passed in through opts (e.g. for node-websql)
function openDatabaseWithOpts(opts) {
return customOpen(opts.name + '.sqlite', 1, null, null, () => {});
}
function openDBSafely(opts) {
try {
return {
db: openDatabaseWithOpts(opts)
};
} catch (err) {
return {
error: err
};
}
}
function openDB(opts) {
var cachedResult = cachedDatabases.get(opts.name);
if (!cachedResult) {
cachedResult = openDBSafely(opts);
cachedDatabases.set(opts.name, cachedResult);
}
return cachedResult;
}
export default openDB;