Skip to content

Commit

Permalink
feat(DBProvider): DBProvider.type
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed May 19, 2020
1 parent 3f30bf1 commit d685078
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AxonClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class AxonClient extends EventEmitter {
/* ADBProvider */
this.DBProvider = new this.extensions.DBProvider(this);
this.DBProvider.init();
this.log('NOTICE', 'DB ready.');
this.log('NOTICE', `DB ready. [TYPE: ${this.DBProvider.type}]`);

if (this.settings.debugMode) {
this.on('debug', this.onDebug);
Expand Down
7 changes: 5 additions & 2 deletions src/Database/ADBProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import NotImplementedException from '../Errors/NotImplementedException';
* guildID: string, prefixes: Array<String>, createdAt: Date, updatedAt: Date, modules: Array<String>, commands: Array<String>, listeners: Array<String>,
* ignoredUsers: Array<String>, ignoredRoles: Array<String>, ignoredChannels: Array<String>, modOnly: Boolean, modRoles: Array<String>, modUsers: Array<String>
* }} GuildConfigRaw
* @typedef {import('../Utility/Constants/AxonEnums').DB_TYPES} DB_TYPES
*/

/**
Expand All @@ -32,16 +33,17 @@ import NotImplementedException from '../Errors/NotImplementedException';
* @class ADBProvider
*
* @prop {AxonClient} axon - The AxonClient
* @prop {DB_TYPES} type - The Database type
*/
class ADBProvider {
/**
* Creates an instance of ADBProvider.
*
* @param {AxonClient} axonClient
*
* @param {DB_TYPES} [type=0]
* @memberof ADBProvider
*/
constructor(axonClient) {
constructor(axonClient, type = 0) {
if (this.constructor === 'ADBProvider') {
throw new NoAbstractInstanceException();
}
Expand All @@ -51,6 +53,7 @@ class ADBProvider {
}

this.axon = axonClient;
this.type = type;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Database/InMemoryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import ADBProvider from './ADBProvider';
* @extends ADBProvider
*/
class InMemoryProvider extends ADBProvider {
constructor(axon) {
super(axon, 0);
}

init() {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/JsonProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import JsonManager from './JSON/JsonManager';
* @prop {JsonManager} manager - Class responsible to read / write data to the DB as json.
*/
class JsonProvider extends ADBProvider {
constructor(axon) {
super(axon, 1);
}

/**
* Override init method.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Database/MongoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import ADBProvider from './ADBProvider';
* @prop {GuildSchema} GuildSchema
*/
class MongoProvider extends ADBProvider {
constructor(axon) {
super(axon, 2);
}

/**
* Override init method.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Loggers/ALogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ALogger {
/**
* Creates an instance of ALogger
* @param out Can be Console, Winston or Signale. Chalk will go as Console
* @param {LOGGER_TYPES} type - The logger type
* @param {LOGGER_TYPES} [type=0] - The logger type
* @memberof ALogger
*/
constructor(out, type = 0) {
Expand Down
8 changes: 6 additions & 2 deletions types/Database/ADBProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AxonClient, AxonConfig, GuildConfig, updateDBVal,
AxonClient, AxonConfig, GuildConfig, updateDBVal, DB_TYPES,
} from '..';

/**
Expand All @@ -19,12 +19,16 @@ export declare abstract class ADBProvider {
* The AxonClient
*/
public axon: AxonClient;
/**
* The Database type
*/
public type: DB_TYPES
/**
* Creates an instance of ADBProvider.
*
* @memberof ADBProvider
*/
constructor(axonClient: AxonClient);
constructor(axonClient: AxonClient, type: DB_TYPES);
/**
* Init the ADBProvider.
* Method called just after instantiation. Can be overridden with anything that will be used by the provider.
Expand Down
2 changes: 2 additions & 0 deletions types/Database/InMemoryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
* @extends ADBProvider
*/
export declare class InMemoryProvider extends ADBProvider {
public type: 0;

public init(): void;
public fetchAxon(): Promise<AxonConfig>;
/**
Expand Down
2 changes: 2 additions & 0 deletions types/Database/JsonProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
* @extends ADBProvider
*/
export declare class JsonProvider extends ADBProvider {
public type: 1;

/**
* Class responsible to read / write data to the DB as json.
*/
Expand Down
2 changes: 2 additions & 0 deletions types/Database/MongoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
* @extends ADBProvider
*/
export declare class MongoProvider extends ADBProvider {
public type: 1;

public AxonSchema?: AxonSchema;
public GuildSchema?: GuildSchema;

Expand Down

0 comments on commit d685078

Please sign in to comment.