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

Add config examples #12

Merged
merged 2 commits into from
Nov 20, 2020
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
31 changes: 31 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@ const successes = await ley.up({ ... });

A config file is entirely optional since `ley` assumes that you're providing the correct environment variable(s) for your client driver. However, that may not always be possible. In those instances, a `ley.config.js` file (default file name) can be used to adjust your [driver](#drivers)'s `connect` method – the file contents are passed directly to this function.

For example, if your hosting provider sets non-standard environment variables for the client driver (like Heroku does), you could extract the information and set the standard environment variables:

```js
// ley.config.js
if (process.env.DATABASE_URL) {
const { parse } = require('pg-connection-string');

// Extract the connection information from the Heroku environment variable
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks!

I generally prefer low-level demonstrations like this (for clarity) but given that connection strings can be pretty wild, do you think it'd make sense to link to pg-connection-string directly for the "official" example?

Could also mention that pg users/drivers can define a connectionString directly, skipping the need to manually parse: https://node-postgres.com/features/connecting#connection-uri

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, switched to pg-connection-string.

I was thinking of also including a comment about pg, but I think that will muddle this specific example, because then it will be about using module.exports again... what do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

Meh, I think this is fine. Users of pg should be able to find the connectionString option on their own. But even if they don't, this configuration works across the board.

const { host, database, user, password } = parse(process.env.DATABASE_URL);

// Set standard environment variables
process.env.PGHOST = host;
process.env.PGDATABASE = database;
process.env.PGUSERNAME = user;
process.env.PGPASSWORD = password;
}
```

Or, if your database provider requires certain SSL connection options to be set in production, you could do that:

```js
// ley.config.js
const options = {};

if (process.env.NODE_ENV === 'production') {
options.ssl = true;
}

module.exports = options;
```

## Drivers

Out of the box, `ley` includes drivers for the following npm packages:
Expand Down