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

Documentation for connection config provider #241

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/bundle.js.map

Large diffs are not rendered by default.

354 changes: 186 additions & 168 deletions index.html

Large diffs are not rendered by default.

42 changes: 41 additions & 1 deletion sections/installation.js
Expand Up @@ -74,7 +74,7 @@ export default [
},
{
type: "text",
content: "The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, or a connection string:"
content: "The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, a connection string, or a function returning an object:"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it still be a connection string?

},
{
type: "info",
Expand Down Expand Up @@ -143,6 +143,46 @@ export default [
});
`
},
{
type: "text",
content: "A function can be used to determine the connection configuration dynamically. This function receives no parameters, and returns either a configuration object or a promise for a configuration object."
},
{
type: "code",
language: "js",
content: `
var knex = require('knex')({
client: 'sqlite3',
connection: () => ({
filename: process.env.SQLITE_FILENAME
})
});
`
},
{
type: "text",
content: "By default, the configuration object received via a function is cached and reused for all connections. To change this behavior, an `expirationChecker` function can be returned as part of the configuration object. The `expirationChecker` is consulted before trying to create new connections, and in case it returns `true`, a new configuration object is retrieved. For example, to work with an authentication token that has a limited lifespan:"
},
{
type: "code",
language: "js",
content: `
var knex = require('knex')({
client: 'postgres',
connection: () => {
const { token, tokenExpiration } = await someCallToGetTheToken();
return {
host : 'your_host',
user : 'your_database_user',
password : token,
database : 'myapp_test',
expirationChecker: () => {
return tokenExpiration <= Date.now();
}
};
});
`
},
{
type: "text",
content: "You can also connect via an unix domain socket, which will ignore host and port."
Expand Down