2020-08-08 00:21:28 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-14 21:46:30 +02:00
|
|
|
stats(options = {}) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
if (!this._initialized) return reject(new Error('MongoDB is not connected.'));
|
|
|
|
this.db.stats(options, (error, result) => {
|
|
|
|
if (error) reject(error);
|
|
|
|
resolve(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:21:28 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-17 22:25:17 +02:00
|
|
|
get webhooks() {
|
|
|
|
return this.tables.webhooks;
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MongoDBProvider;
|