-
Notifications
You must be signed in to change notification settings - Fork 0
sql.js
Christoph Herrmann edited this page Jan 20, 2022
·
2 revisions
If you don't want to use the default connection with the env var DATABASE_URL or dislike the connection establishment with the first query, you can create a sql.js file in your project directory:
module.exports = async () => {
const { Client } = require('pg')
const client = new Client({ connectionString: process.env.DATABASE_URL })
await client.connect()
const sql = require('sql-pg')({ client })
return { client, sql }
}And use it in your project:
const path = require('path')
;(async () => {
const { sql } = await require(path.join(process.cwd(), 'sql.js'))()
})()The migration script will also use this file if it exists.
Found a bug or missing a feature? -> Create a new Issue
Found a security issue? -> Look at the Security Policy
Having questions, want to give feedback or talk to me? -> E-Mail me sql-pg@sharaal.de