Compare commits
No commits in common. "6b121937f7e21176596e48e4c2c57f0ce9c46ff6" and "a501f86ef6842534d435384f16907efffbe099fc" have entirely different histories.
6b121937f7
...
a501f86ef6
1 changed files with 11 additions and 8 deletions
11
src/db.ts
11
src/db.ts
|
@ -11,16 +11,19 @@ import { insertResponse, readResponse, writeResponse, singleResponse } from "./r
|
||||||
export class DB {
|
export class DB {
|
||||||
tables: Table[] = [];
|
tables: Table[] = [];
|
||||||
handler!: Handler;
|
handler!: Handler;
|
||||||
name!: string;
|
name: string;
|
||||||
type!: dbType;
|
type!: dbType;
|
||||||
mariaPool!: mariadb.Pool;
|
mariaPool!: mariadb.Pool;
|
||||||
private connected = false;
|
private connected = false;
|
||||||
//pgPool!: pg.Pool;
|
//pgPool!: pg.Pool;
|
||||||
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 }) {
|
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 }) {
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.type = databaseType;
|
this.type = databaseType;
|
||||||
if (databaseType == dbType.mariadb) {
|
if (databaseType == dbType.mariadb) {
|
||||||
this.mariaPool = mariadb.createPool({ host, user, password, port, database, connectionLimit, multipleStatements: true });
|
this.mariaPool = mariadb.createPool({ host, user, password, port, database: this.name, connectionLimit, multipleStatements: true });
|
||||||
this.handler = new Handler(this);
|
this.handler = new Handler(this);
|
||||||
}
|
}
|
||||||
/*else if (databaseType == dbType.postgres) {
|
/*else if (databaseType == dbType.postgres) {
|
||||||
|
@ -29,7 +32,7 @@ export class DB {
|
||||||
}*/
|
}*/
|
||||||
else throw new Error("Unsuported Database type!");
|
else throw new Error("Unsuported Database type!");
|
||||||
|
|
||||||
this.name = database;
|
|
||||||
}
|
}
|
||||||
async query(query: Query, printQuery = false) {
|
async query(query: Query, printQuery = false) {
|
||||||
if(!this.connected) throw new Error("Not connected yet!");
|
if(!this.connected) throw new Error("Not connected yet!");
|
||||||
|
|
Loading…
Reference in a new issue