| '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; |