Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
John B committed Mar 31, 2022
1 parent 59b6f12 commit 415f366
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/lib/database/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import * as T from "./type";
// see: https://dev.mysql.com/doc/mysql-port-reference/en/mysql-ports-reference-tables.html#mysql-client-server-ports
const mysqlDefaultPort = 3306;

export interface ConnectionOptions {
host: string;
user: string;
password: string;
database: string;
port: number;
ssl?: string | SslOptions;
}

export class SQL {
//connection: mysql.Connection;
pool: T.Pool;
Expand All @@ -16,14 +25,7 @@ export class SQL {
database,
port = mysqlDefaultPort,
ssl,
}: {
host: string;
user: string;
password: string;
database: string;
port: number;
ssl?: string | SslOptions;
}) {
}: ConnectionOptions) {
const config: PoolOptions = {
host,
user,
Expand Down
11 changes: 2 additions & 9 deletions src/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// this file is used for the package. The server should use the other files directly
import * as Connection from "./database/connection";
import { Database } from "./database/type";
import * as Exec from "./exec";
import * as T from "./type";
import { addColumnsToModel } from "./model/utils";
Expand All @@ -17,17 +16,11 @@ export class Main {
options: Options;

constructor(
c: Database,
c: Connection.ConnectionOptions,
model: T.Entity[],
options: Options = { legacyMode: false }
) {
this.s = new Connection.SQL(
c.host,
c.username,
c.password,
c.database,
c.port
);
this.s = new Connection.SQL(c);

addColumnsToModel(model);
this.model = model;
Expand Down
16 changes: 9 additions & 7 deletions src/service/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export const getPool = (
const pool = Connection.databases.get(pid);

if (!pool) {
const pool = new Connection.SQL(
db.host,
db.username,
db.password,
db.database,
db.port
);
const connection = {
host: db.host,
user: db.username,
password: db.password,
port: db.port,
database: db.database,
};

const pool = new Connection.SQL(connection);
Connection.databases.set(pid, pool);

return pool;
Expand Down

0 comments on commit 415f366

Please sign in to comment.