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

Let connection pool size be configured #107

Merged
merged 1 commit into from
Aug 23, 2023
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
8 changes: 6 additions & 2 deletions packages/common-ts/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ interface ConnectOptions {
password: string
database: string
logging?: (sql: string, timing?: number) => void
poolMin?: number
poolMax?: number
}

export const connectDatabase = async (options: ConnectOptions): Promise<Sequelize> => {
const { host, username, password, database, logging } = options

// Use port 5432 by default
const port = options.port || 5432
const poolMin = options.poolMin || 0
const poolMax = options.poolMax || 10

// Connect to the database
const sequelize = new Sequelize({
Expand All @@ -24,8 +28,8 @@ export const connectDatabase = async (options: ConnectOptions): Promise<Sequeliz
password,
database,
pool: {
max: 10,
min: 0,
max: poolMax,
min: poolMin,
},
logging,
})
Expand Down
Loading