Skip to content

Commit f5da929

Browse files
authored
chore: add config examples to readme (#12)
* Add config examples * Use pg-connection-string instead of url
1 parent 162d1a7 commit f5da929

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

readme.md

+31
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,37 @@ const successes = await ley.up({ ... });
154154
155155
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.
156156
157+
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:
158+
159+
```js
160+
// ley.config.js
161+
if (process.env.DATABASE_URL) {
162+
const { parse } = require('pg-connection-string');
163+
164+
// Extract the connection information from the Heroku environment variable
165+
const { host, database, user, password } = parse(process.env.DATABASE_URL);
166+
167+
// Set standard environment variables
168+
process.env.PGHOST = host;
169+
process.env.PGDATABASE = database;
170+
process.env.PGUSERNAME = user;
171+
process.env.PGPASSWORD = password;
172+
}
173+
```
174+
175+
Or, if your database provider requires certain SSL connection options to be set in production, you could do that:
176+
177+
```js
178+
// ley.config.js
179+
const options = {};
180+
181+
if (process.env.NODE_ENV === 'production') {
182+
options.ssl = true;
183+
}
184+
185+
module.exports = options;
186+
```
187+
157188
## Drivers
158189
159190
Out of the box, `ley` includes drivers for the following npm packages:

0 commit comments

Comments
 (0)