Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Named Instances for Microsoft Sql Server #204

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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