galactic-bot/structure/storage/providers/Mongodb.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

const { Provider } = require('../interfaces/');
const { MongoClient } = require('mongodb');
class MongoDBProvider extends Provider {
constructor(client, config) {
super(client, {
name: 'mongodb',
config
});
}
async initialize() {
try {
this.connection = await MongoClient.connect(this.config.host+this.config.database, { useUnifiedTopology: true });
this.db = await this.connection.db(this.config.database);
return this._initialized = true; //eslint-disable-line no-return-assign
} catch(err) {
this._error(err);
return false;
}
}
get guilds() {
return this.tables.guilds;
}
get permissions() {
return this.tables.permissions;
}
get infractions() {
return this.tables.infractions;
}
get messages() {
return this.tables.messages;
}
get attachments() {
return this.tables.attachments;
}
get users() {
return this.tables.users;
}
2020-08-09 01:23:48 +02:00
get role_cache() {
return this.tables.role_cache;
}
}
module.exports = MongoDBProvider;