diff --git a/src/lib/database/connection.ts b/src/lib/database/connection.ts index 1c7b0df..304509c 100644 --- a/src/lib/database/connection.ts +++ b/src/lib/database/connection.ts @@ -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; @@ -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, diff --git a/src/lib/main.ts b/src/lib/main.ts index a6adff5..1ecba96 100644 --- a/src/lib/main.ts +++ b/src/lib/main.ts @@ -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"; @@ -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; diff --git a/src/service/database/index.ts b/src/service/database/index.ts index 1fac730..3dd165d 100644 --- a/src/service/database/index.ts +++ b/src/service/database/index.ts @@ -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;