Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/natural/util/storage/StorageBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

const PostgresPlugin = require('./Postgres')
const MongoDBPlugin = require('./MongoDB')
const RedisPlugin = require('./Redis')
const MemcachedPlugin = require('./Memcached')
const FilePlugin = require('./File')

// Enum for different types of storage backends that can be used
const STORAGE_TYPES = {
POSTGRES: 'POSTGRES',
Expand All @@ -49,6 +43,8 @@ class StorageBackend {
}

// Sets the storage type. Valid values are POSTGRES, REDIS, MONGODB, MEMCACHED, FILE
// Storage plugins are loaded on demand to avoid pulling in database drivers
// and their dependencies for users who only need NLP features.
async setStorageType (storageType) {
if (!storageType) {
throw new Error('No storage type specified')
Expand All @@ -58,22 +54,32 @@ class StorageBackend {
}
this.storageType = storageType
switch (storageType) {
case STORAGE_TYPES.POSTGRES:
case STORAGE_TYPES.POSTGRES: {
const PostgresPlugin = require('./Postgres')
this.client = new PostgresPlugin()
await this.client.configPostgres()
break
case STORAGE_TYPES.REDIS:
}
case STORAGE_TYPES.REDIS: {
const RedisPlugin = require('./Redis')
this.client = new RedisPlugin()
break
case STORAGE_TYPES.MONGODB:
}
case STORAGE_TYPES.MONGODB: {
const MongoDBPlugin = require('./MongoDB')
this.client = new MongoDBPlugin()
break
case STORAGE_TYPES.MEMCACHED:
}
case STORAGE_TYPES.MEMCACHED: {
const MemcachedPlugin = require('./Memcached')
this.client = new MemcachedPlugin()
break
case STORAGE_TYPES.FILE:
}
case STORAGE_TYPES.FILE: {
const FilePlugin = require('./File')
this.client = new FilePlugin()
break
}
default:
throw new Error('Invalid storage type')
}
Expand Down