Skip to content
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.

Clone this wiki locally