From e374caf6660412beb5b77cfc82543b598a31fea4 Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Thu, 22 Feb 2024 12:05:54 +0100 Subject: [PATCH] fix mysql connection string --- package.json | 6 ++++-- src/utils/connect.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 35fa967..3665887 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,14 @@ { "name": "@dashpress/bacteria", - "version": "0.0.11", + "version": "0.0.12", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Ayobami Akingbade", "module": "dist/bacteria.esm.js", - "files": ["dist"], + "files": [ + "dist" + ], "scripts": { "test": "jest --detectOpenHandles --runInBand", "start": "tsdx watch", diff --git a/src/utils/connect.ts b/src/utils/connect.ts index 5e71e29..9ca7f3c 100644 --- a/src/utils/connect.ts +++ b/src/utils/connect.ts @@ -14,7 +14,7 @@ const SupportedDataSourceToKnexClientMap: Record< const handleStringCredentials = (credentials: string) => { if (credentials.startsWith("sqlite")) { return knex({ - client: "better-sqlite3", + client: SupportedDataSourceToKnexClientMap[RDMSSources.Sqlite], connection: { filename: credentials.split(":")[1], }, @@ -22,6 +22,20 @@ const handleStringCredentials = (credentials: string) => { }); } + if (credentials.startsWith("mysql:")) { + return knex({ + client: SupportedDataSourceToKnexClientMap[RDMSSources.MySql], + connection: credentials, + }); + } + + if (credentials.startsWith("mssql:")) { + return knex({ + client: SupportedDataSourceToKnexClientMap[RDMSSources.MsSql], + connection: credentials, + }); + } + return knex(credentials); };