Skip to content

Commit

Permalink
fix(configuration): Add pool and connection object to SQL database de…
Browse files Browse the repository at this point in the history
…fault configuration (#3023)
  • Loading branch information
daffl authored Jan 29, 2023
1 parent 3692fd5 commit 092c749
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
28 changes: 28 additions & 0 deletions docs/guides/cli/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ Depending on the SQL database you selected, a `src/<database>.ts` file will be c
const knex = app.get('<database>Client')
```

The database pool size can be set in the [configuration](./default.json.md) like this:

```json
"postgresql": {
"client": "pg",
"connection": "<pg connection string>",
"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"
}
}
```

</DatabaseBlock>

<DatabaseBlock global-id="mongodb">
Expand Down
23 changes: 22 additions & 1 deletion packages/schema/src/default-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion packages/typebox/src/default-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
)
})
)

Expand Down

0 comments on commit 092c749

Please # to comment.