Skip to content

Commit

Permalink
add support from msnodesqlv8
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Oct 18, 2024
1 parent 7636b72 commit 06c882a
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 10 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import Debug from 'debug';
import exitHook from 'exit-hook';
import mssql from 'mssql';
import msNodeSql from 'mssql/msnodesqlv8.js';
const debug = Debug('mssql-multi-pool:index');
const POOLS = new Map();
function getPoolKey(config) {
return `${config.user ?? ''}@${config.server}/${config.options?.instanceName ?? ''};${config.database ?? ''}`;
return `${config.user ?? ''}@${config.server}/${config.options?.instanceName ?? ''};${config.database ?? ''};${config.driver ?? 'tedious'}`;
}
export async function connect(config) {
const poolKey = getPoolKey(config);
let pool = POOLS.get(poolKey);
if (!(pool?.connected ?? false)) {
debug(`New database connection: ${poolKey}`);
pool = await new mssql.ConnectionPool(config).connect();
pool =
(config.driver ?? '') === 'msnodesqlv8'
? await new msNodeSql.ConnectionPool(config).connect()
: await new mssql.ConnectionPool(config).connect();
POOLS.set(poolKey, pool);
}
return pool;
Expand Down
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Debug from 'debug'
import exitHook from 'exit-hook'
import mssql from 'mssql'
import msNodeSql from 'mssql/msnodesqlv8.js'

const debug = Debug('mssql-multi-pool:index')

Expand All @@ -9,7 +10,7 @@ const POOLS = new Map<string, mssql.ConnectionPool>()
function getPoolKey(config: mssql.config): string {
return `${config.user ?? ''}@${config.server}/${
config.options?.instanceName ?? ''
};${config.database ?? ''}`
};${config.database ?? ''};${config.driver ?? 'tedious'}`
}

/**
Expand All @@ -28,7 +29,10 @@ export async function connect(
if (!(pool?.connected ?? false)) {
debug(`New database connection: ${poolKey}`)

pool = await new mssql.ConnectionPool(config).connect()
pool =
(config.driver ?? '') === 'msnodesqlv8'
? await new msNodeSql.ConnectionPool(config).connect()
: await new mssql.ConnectionPool(config).connect()
POOLS.set(poolKey, pool)
}

Expand Down
Loading

0 comments on commit 06c882a

Please sign in to comment.