Skip to content

Commit

Permalink
docs: provide more usage patterns for Knex configuration object (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Jul 11, 2023
1 parent 19971b2 commit 9d8ae29
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ const pg = require('knex')({
```
:::

When using the PostgreSQL driver, another usage pattern for instantiating the Knex configuration object could be to use a `connection: {}` object details to specify various flags such as enabling SSL, a connection string, and individual connection configuration fields all in the same object. Consider the following example:

::: info PostgreSQL
If `connectionString` is highest priority to use. If left unspecified then connection details will be determined using the individual connection fields (`host`, `port`, etc), and finally an SSL configuration will be enabled based on a truthy value of `config["DB_SSL"]` which will also accept self-signed certificates.

```js
const pg = require('knex')({
client: 'pg',
connection: {
connectionString: config.DATABASE_URL,
host: config["DB_HOST"],
port: config["DB_PORT"],
user: config["DB_USER"],
database: config["DB_NAME"],
password: config["DB_PASSWORD"],
ssl: config["DB_SSL"] ? { rejectUnauthorized: false } : false,
}
});
```
:::

The following are SQLite usage patterns for instantiating the Knex configuration object:

::: info SQLite3 or Better-SQLite3
When you use the SQLite3 or Better-SQLite3 adapter, there is a filename required, not a network connection. For example:

Expand Down

0 comments on commit 9d8ae29

Please sign in to comment.