Skip to content

Commit

Permalink
Support instance name for Microsoft Sql Server
Browse files Browse the repository at this point in the history
  • Loading branch information
gittgott authored and RobinBlomberg committed Oct 17, 2024
1 parent af195fd commit 462bf4d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/introspector/dialects/mssql/mssql-dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ export class MssqlIntrospectorDialect extends IntrospectorDialect {
string
>;
const tokens = parsed.server!.split(',');
const server = tokens[0]!;
const port = tokens[1]
? Number.parseInt(tokens[1], 10)
: DEFAULT_MSSQL_PORT;

const serverAndInstance = tokens[0]!.split('\\');
const server = serverAndInstance[0]!;
const instanceName = serverAndInstance[1];
/**
* Instance name and port are mutually exclusive
* @see https://tediousjs.github.io/tedious/api-connection.html#:~:text=options.instanceName
*/
const port =
instanceName === undefined
? tokens[1]
? Number.parseInt(tokens[1], 10)
: DEFAULT_MSSQL_PORT
: undefined;
return {
database: parsed.database!,
instanceName,
password: parsed.password!,
port,
server,
Expand All @@ -39,7 +48,7 @@ export class MssqlIntrospectorDialect extends IntrospectorDialect {
const tarn = await import('tarn');
const tedious = await import('tedious');

const { database, password, port, server, userName } =
const { database, instanceName, password, port, server, userName } =
await this.#parseConnectionString(options.connectionString);

return new KyselyMssqlDialect({
Expand All @@ -58,6 +67,7 @@ export class MssqlIntrospectorDialect extends IntrospectorDialect {
options: {
database,
encrypt: options.ssl ?? true,
instanceName,
port,
trustServerCertificate: true,
},
Expand Down

0 comments on commit 462bf4d

Please sign in to comment.