Skip to content

Commit 73a972f

Browse files
drew-u410dwerner
authored andcommitted
[db] add ability to enable SSL for database connection
1 parent f118c45 commit 73a972f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

packages/common-ts/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Add ability to enable SSL to database connection with `sslEnabled` (maintain default of `false`)
810

911
## [2.0.7] - 2023-09-25
1012
### Changed

packages/common-ts/src/database/index.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,45 @@ describe('Database', () => {
1010
const sequelize = await connectDatabase(__DATABASE__)
1111
expect(sequelize).toBeDefined()
1212
})
13+
14+
test('Connect with options set', async () => {
15+
const sequelize = await connectDatabase({
16+
host: 'localhost',
17+
username: 'test',
18+
password: 'test',
19+
database: 'test',
20+
sslEnabled: true,
21+
logging: () => {},
22+
poolMin: 1,
23+
poolMax: 5,
24+
})
25+
26+
expect(sequelize).toBeDefined()
27+
28+
const poolConfig = sequelize.config.pool
29+
expect(poolConfig?.min).toBe(1)
30+
expect(poolConfig?.max).toBe(5)
31+
32+
const sslConfig = sequelize.config.ssl
33+
expect(sslConfig).toBe(true)
34+
})
35+
36+
test('Connect with default options', async () => {
37+
const sequelize = await connectDatabase({
38+
host: 'localhost',
39+
username: 'test',
40+
password: 'test',
41+
database: 'test',
42+
logging: () => {},
43+
})
44+
45+
expect(sequelize).toBeDefined()
46+
47+
const poolConfig = sequelize.config.pool
48+
expect(poolConfig?.min).toBe(0)
49+
expect(poolConfig?.max).toBe(10)
50+
51+
const sslConfig = sequelize.config.ssl
52+
expect(sslConfig).toBe(false)
53+
})
1354
})

packages/common-ts/src/database/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface ConnectOptions {
66
username: string
77
password: string
88
database: string
9+
sslEnabled?: boolean
910
logging?: (sql: string, timing?: number) => void
1011
poolMin?: number
1112
poolMax?: number
@@ -18,6 +19,7 @@ export const connectDatabase = async (options: ConnectOptions): Promise<Sequeliz
1819
const port = options.port || 5432
1920
const poolMin = options.poolMin || 0
2021
const poolMax = options.poolMax || 10
22+
const sslEnabled = options.sslEnabled || false
2123

2224
// Connect to the database
2325
const sequelize = new Sequelize({
@@ -27,6 +29,7 @@ export const connectDatabase = async (options: ConnectOptions): Promise<Sequeliz
2729
username,
2830
password,
2931
database,
32+
ssl: sslEnabled,
3033
pool: {
3134
max: poolMax,
3235
min: poolMin,

0 commit comments

Comments
 (0)