-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convertJdbcToDsn utility function (#619)
* feat: convert-jdbc-to-dsn helper * docs: api doc updated * docs: api doc updated * feat: convert-jdbc-to-dsn helper --------- Co-authored-by: Sebastien Vanvelthem <sebastien.vanvelthem@weareretail.ai>
- Loading branch information
1 parent
017071b
commit b7587cd
Showing
10 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
'@httpx/dsn-parser': minor | ||
--- | ||
|
||
Add convertJdbcToDsn utility function | ||
|
||
Helps to convert [jdbc](https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15) dsn. | ||
Useful for prisma using [sqlserver](https://www.prisma.io/docs/concepts/database-connectors/sql-server#connection-details). | ||
|
||
```typescript | ||
import { convertJdbcToDsn } from '@httpx/dsn-parser'; | ||
|
||
const jdbcDsn = | ||
'sqlserver://localhost:1433;database=my-db;authentication=default;user=sa;password=pass03$;encrypt=true;trustServerCertificate=true'; | ||
|
||
const dsn = convertJdbcToDsn(jdbc); | ||
|
||
// -> 'sqlserver://localhost:1433?database=my-db&authentication=default&user=sa&password=pass03$&encrypt=true&trustServerCertificate=true' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/dsn-parser/src/__tests__/convert-jdbc-to-dsn.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { convertJdbcToDsn } from '../convert-jdbc-to-dsn'; | ||
import { parseDsnOrThrow } from '../parse-dsn-or-throw'; | ||
|
||
describe('convertJdbcToDsn', () => { | ||
it('should return a dsn string from a valid jdbc string', () => { | ||
const jdbc = | ||
'sqlserver://localhost:1433;database=my-db;authentication=default;user=sa;password=pass03$;encrypt=true;trustServerCertificate=true'; | ||
const dsn = convertJdbcToDsn(jdbc); | ||
expect(dsn).toStrictEqual( | ||
'sqlserver://localhost:1433?database=my-db&authentication=default&user=sa&password=pass03$&encrypt=true&trustServerCertificate=true' | ||
); | ||
expect(parseDsnOrThrow(dsn)).toStrictEqual({ | ||
driver: 'sqlserver', | ||
host: 'localhost', | ||
port: 1433, | ||
params: { | ||
authentication: 'default', | ||
database: 'my-db', | ||
encrypt: true, | ||
password: 'pass03$', | ||
trustServerCertificate: true, | ||
user: 'sa', | ||
}, | ||
}); | ||
}); | ||
it('should return a dsn string from a minimal jdbc dsn', () => { | ||
const jdbc = 'sqlserver://localhost:1433'; | ||
const dsn = convertJdbcToDsn(jdbc); | ||
expect(dsn).toStrictEqual('sqlserver://localhost:1433'); | ||
expect(parseDsnOrThrow(dsn)).toStrictEqual({ | ||
driver: 'sqlserver', | ||
host: 'localhost', | ||
port: 1433, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const convertJdbcToDsn = (jdbc: string): string => { | ||
const [part1, ...rest] = jdbc.split(';'); | ||
return [part1, rest ? rest.join('&') : undefined] | ||
.filter((v) => Boolean(v)) | ||
.join('?'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@httpx/json-api | ||
|
||
# @httpx/json-api - v0.4.0 | ||
# @httpx/json-api - v0.4.1 | ||
|
||
## Table of contents | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters