Compare commits

..

2 commits

Author SHA1 Message Date
6b121937f7 Merge pull request 'moved db name' (#12) from dev into main
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
Reviewed-on: #12
2023-02-25 19:22:01 +01:00
09d43f8f98 moved db name
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2023-02-25 19:20:59 +01:00

View file

@ -11,19 +11,16 @@ import { insertResponse, readResponse, writeResponse, singleResponse } from "./r
export class DB {
tables: Table[] = [];
handler!: Handler;
name: string;
name!: string;
type!: dbType;
mariaPool!: mariadb.Pool;
private connected = false;
//pgPool!: pg.Pool;
constructor(database: string) {
this.name = database;
}
connect({ host, user, password, port = 3306, connectionLimit = 5, databaseType = dbType.mariadb }: { host: string, user: string, password: string, port?: number, connectionLimit?: number, databaseType?: dbType }) {
connect({ host, user, password, database, port = 3306, connectionLimit = 5, databaseType = dbType.mariadb }: { host: string, user: string, password: string, database: string, port?: number, connectionLimit?: number, databaseType?: dbType }) {
this.connected = true;
this.type = databaseType;
if (databaseType == dbType.mariadb) {
this.mariaPool = mariadb.createPool({ host, user, password, port, database: this.name, connectionLimit, multipleStatements: true });
this.mariaPool = mariadb.createPool({ host, user, password, port, database, connectionLimit, multipleStatements: true });
this.handler = new Handler(this);
}
/*else if (databaseType == dbType.postgres) {
@ -32,10 +29,10 @@ export class DB {
}*/
else throw new Error("Unsuported Database type!");
this.name = database;
}
async query(query: Query, printQuery = false) {
if(!this.connected) throw new Error("Not connected yet!");
if (!this.connected) throw new Error("Not connected yet!");
if (printQuery) console.log(query);
if (this.type == dbType.mariadb) return await this.mariaPool.query(query);
/*else if (this.type == dbType.postgres) {
@ -46,12 +43,12 @@ export class DB {
else throw new Error("Invalid Database Type!");
}
getHandler() {
if(!this.connected) throw new Error("Not connected yet!");
if (!this.connected) throw new Error("Not connected yet!");
return this.handler;
}
async sync(force = false) {
if(!this.connected) throw new Error("Not connected yet!");
if (!this.connected) throw new Error("Not connected yet!");
let handler = this.getHandler();
await handler.syncDB(this, handler, force);
}
@ -67,7 +64,7 @@ export class DB {
return null;
}
async close() {
if(!this.connected) throw new Error("Not connected yet!");
if (!this.connected) throw new Error("Not connected yet!");
if (this.type == dbType.mariadb && this.mariaPool) await this.mariaPool.end();
//if (this.type == dbType.postgres && this.pgPool) await this.pgPool.end();
}