From 092c749d43f7da4d019576d1210fe7d3719a44a2 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Sun, 29 Jan 2023 09:16:24 -0800 Subject: [PATCH] fix(configuration): Add pool and connection object to SQL database default configuration (#3023) --- docs/guides/cli/databases.md | 28 +++++++++++++++++++++++++ packages/schema/src/default-schemas.ts | 23 +++++++++++++++++++- packages/typebox/src/default-schemas.ts | 19 ++++++++++++++++- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/docs/guides/cli/databases.md b/docs/guides/cli/databases.md index 81c4620a15..803695bb2c 100644 --- a/docs/guides/cli/databases.md +++ b/docs/guides/cli/databases.md @@ -17,6 +17,34 @@ Depending on the SQL database you selected, a `src/.ts` file will be c const knex = app.get('Client') ``` +The database pool size can be set in the [configuration](./default.json.md) like this: + +```json +"postgresql": { + "client": "pg", + "connection": "", + "pool": { + "min": 0, + "max": 7 + } +}, +``` + +`connection` can also be an object instead of a connection string: + +```json +"postgresql": { + "client": "pg", + "connection": { + "host": "localhost", + "port": 5432, + "user": "postgres", + "password": "postgres", + "database": "pgtest" + } +} +``` + diff --git a/packages/schema/src/default-schemas.ts b/packages/schema/src/default-schemas.ts index a3ef7726c3..810af0677a 100644 --- a/packages/schema/src/default-schemas.ts +++ b/packages/schema/src/default-schemas.ts @@ -117,7 +117,28 @@ export const sqlSettingsSchema = { type: 'object', properties: { client: { type: 'string' }, - connection: { type: 'string' } + pool: { + type: 'object', + properties: { + min: { type: 'number' }, + max: { type: 'number' } + } + }, + connection: { + oneOf: [ + { type: 'string' }, + { + type: 'object', + properties: { + host: { type: 'string' }, + port: { type: 'number' }, + user: { type: 'string' }, + password: { type: 'string' }, + database: { type: 'string' } + } + } + ] + } } } as const diff --git a/packages/typebox/src/default-schemas.ts b/packages/typebox/src/default-schemas.ts index e5dd715db5..3823e6c5b7 100644 --- a/packages/typebox/src/default-schemas.ts +++ b/packages/typebox/src/default-schemas.ts @@ -58,7 +58,24 @@ export const authenticationSettingsSchema = Type.Object({ export const sqlSettingsSchema = Type.Optional( Type.Object({ client: Type.String(), - connection: Type.String() + connection: Type.Union([ + Type.String(), + Type.Partial( + Type.Object({ + host: Type.String(), + port: Type.Number(), + user: Type.String(), + password: Type.String(), + database: Type.String() + }) + ) + ]), + pool: Type.Optional( + Type.Object({ + min: Type.Number(), + max: Type.Number() + }) + ) }) )