Browse Source

Automatically require storage adapter via uri or opts.adapter

emp
Luke Childs 7 years ago
committed by Jytesh
parent
commit
7890a9c367
  1. 18
      packages/keyv/src/index.js

18
packages/keyv/src/index.js

@ -1,9 +1,21 @@
'use strict'; 'use strict';
const adapters = {
redis: 'keyv-redis',
mongodb: 'keyv-mongo'
};
class Keyv { class Keyv {
constructor(opts) { constructor(uri, opts) {
this.opts = opts || {}; this.opts = Object.assign(
this.opts.store = this.opts.store || new Map(); {},
(typeof uri === 'string') ? { uri, adapter: uri.match(/^[^:]*/)[0] } : uri,
opts
);
if (!this.opts.store) {
this.opts.store = this.opts.adapter ? new (require(adapters[this.opts.adapter]))(opts) : new Map();
}
} }
get(key) { get(key) {

Loading…
Cancel
Save