Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tediousjs/connection-string

tediousjs3.4mMIT0.6.0TypeScript support: included

SQL ConnectionString parser

mssql, tsql, connectionstring

readme

Connection String Parser

npm version Lint, Test & Release

This node library is designed to allow the parsing of Connection Strings see https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring

The library also provides the ability to parse SQL Connection Strings.

Usage

Parsing connection strings

The library comes with a generic connection string parser that will parse through valid connections strings and produce a key-value map of the entries in that string. No additional validation is performed.

const { parseConnectionString } = require('@tediousjs/connection-string');

const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';

const parsed = parseConnectionString(connectionString);

console.log(parsed);

Output to the console will be:

{
  "User id": "user",
  "password": "password",
  "initial catalog": "AdventureWorks",
  "server": "MySqlServer"
}

Parsing SQL connection strings

There is a specific helper for parsing SQL connection strings and this comes with a value normaliser and validation. It also has an option to "canonicalise" the properties. For many properties in an SQL connections string, there are aliases, when canonical properties are being used, these aliases will be returned as the canonical property.

const { parseSqlConnectionString } = require('@tediousjs/connection-string');

const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';

const parsed = parseSqlConnectionString(connectionString, true);

console.log(parsed);

Output to console will be:

{
  "user id": "user",
  "password": "password",
  "initial catalog": "AdventureWorks",
  "data source": "MySqlServer"
}

NB: The Server property from the connection string has been re-written to the value Data Source

changelog

Changelog

0.6.0 (2024-09-11)

Features

  • add more authentication options (cae1d20)

0.5.0 (2023-08-09)

Features

  • add connection string builder (369a63f)

0.4.4 (2023-08-02)

Bug Fixes

0.4.3 (2023-08-01)

Bug Fixes

0.4.2 (2023-08-01)

Bug Fixes

  • update return types for parsers (bb6393a)

v0.4.2 (2023-01-19)

  • Fix bug with parsing string values that start with numbers

v0.4.1 (2022-06-07)

  • Add missing type declarations

v0.4.0 (2022-04-27)

  • Add LICENSE file (MIT) #17
  • Improve library code / TS definitions #18
  • Dependency updates

v0.3.0 (2021-01-21)

  • Allow parsed SQL connection strings to return unrecognised properties #4

v0.2.0 (2021-01-21)

  • Parsed query strings return lowercase keys #3

v0.1.0 (2021-01-21)

Initial release