changed Project Stucture - Part2
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export interface IJsonDao {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import {IJsonDao} from "./IJsonDao";
|
||||
import {Config, JsonDB} from "node-json-db";
|
||||
|
||||
export class JsonDao implements IJsonDao {
|
||||
private _jsonDatabaseContext: JsonDB;
|
||||
|
||||
constructor(fileLocation: string) {
|
||||
this._jsonDatabaseContext = new JsonDB(new Config(fileLocation, true, false, "/", true));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface IMySqlDao {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import {IMySqlDao} from "./IMySqlDao";
|
||||
import mysql, {Connection, ConnectionOptions} from 'mysql2/promise';
|
||||
import {Connection as BaseConnection} from "mysql2/typings/mysql/lib/Connection";
|
||||
|
||||
export class MysqlDao implements IMySqlDao {
|
||||
private _mysqlDatabaseContext!: Connection;
|
||||
|
||||
constructor(mysqlAuthenticationData: ConnectionOptions) {
|
||||
this.InitializeDatabaseContext(mysqlAuthenticationData).catch(error => {
|
||||
throw new Error(error)
|
||||
});
|
||||
}
|
||||
|
||||
private async InitializeDatabaseContext(mysqlAuthenticationData: ConnectionOptions): Promise<void> {
|
||||
this._mysqlDatabaseContext = await mysql.createConnection(mysqlAuthenticationData);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,19 @@
|
||||
import {JsonDatabaseServices} from "../../InternalServices/DatabaseServices/JsonDatabaseServices";
|
||||
import {MySqlDatabaseServices} from "../../InternalServices/DatabaseServices/MySqlDatabaseServices";
|
||||
import {Constants} from "../../Core/Contants";
|
||||
import {ConnectionOptions} from "mysql2/promise";
|
||||
|
||||
export class AudioStreamManager {
|
||||
constructor(
|
||||
databaseType: "Json" | "MySql",
|
||||
databaseOptions: {
|
||||
Host: string;
|
||||
Port: number;
|
||||
Username: string;
|
||||
Password: string;
|
||||
Database: string;
|
||||
} | string) {
|
||||
|
||||
constructor(databaseType: "Json" | "MySql", databaseOptions: ConnectionOptions | string) {
|
||||
if (databaseType === "MySql" &&
|
||||
databaseOptions &&
|
||||
typeof databaseOptions === "object") {
|
||||
console.log("mysql passed")
|
||||
Constants.DatabaseServices = new MySqlDatabaseServices(databaseOptions);
|
||||
} else if (databaseType === "Json" &&
|
||||
databaseOptions &&
|
||||
typeof databaseOptions === "string") {
|
||||
console.log("json passed")
|
||||
Constants.DatabaseServices = new JsonDatabaseServices(databaseOptions);
|
||||
} else {
|
||||
console.log("err passed")
|
||||
throw new Error("Failed validating database.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import {IDatabaseServices} from "./IDatabaseServices";
|
||||
import {JsonDao} from "../../DataAccess/Json/JsonDao";
|
||||
|
||||
export class JsonDatabaseServices implements IDatabaseServices {
|
||||
constructor(databaseOptions : string) {
|
||||
// IMPLEMENT DATABASE
|
||||
private _databaseDao: JsonDao;
|
||||
|
||||
constructor(databaseOptions : any) {
|
||||
this._databaseDao = new JsonDao(databaseOptions);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
import {IDatabaseServices} from "./IDatabaseServices";
|
||||
import {MysqlDao} from "../../DataAccess/MySql/MysqlDao";
|
||||
import {ConnectionOptions} from "mysql2/promise";
|
||||
|
||||
export class MySqlDatabaseServices implements IDatabaseServices {
|
||||
private _databaseDao: MysqlDao;
|
||||
|
||||
constructor(databaseOptions: {
|
||||
Host: string;
|
||||
Port: number;
|
||||
Username: string;
|
||||
Password: string;
|
||||
Database: string;
|
||||
}) {
|
||||
//IMPLEMENT DATABASE
|
||||
constructor(databaseOptions: ConnectionOptions) {
|
||||
this._databaseDao = new MysqlDao(databaseOptions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user