pg-boss
pg-boss copied to clipboard
Documentation for PgBoss constructor db option.
This is a documentation improvement idea
I think the Database Install chapter of readme may be improved to include example of initializing PgBoss with external db connection.
In my case I have Node + Typescript app that uses Sequelize for db connection and ORM. Db is configured differently for local dev environment (no ssl) and production (with SSL).
I was struggling to find the correct way to use Sequelize for db access for PgBoss. Here is what worked for me:
//// db contains all the parameters for connection string, ssl options, etc. and is defined elsewhere
//// The same instance of Sequelize is reused in the code that initializes PgBoss
// const db = new Sequelize(...)
const executeSql = async (text: string, values: string[]): Promise<{ rows: any[], rowCount: number }> => {
const [rows] = await db.query(text, { bind: values })
return { rows, rowCount: rows.length }
}
const pgDb = { executeSql }
const boss = new PgBoss({ db: pgDb })
If this was included in the documentation it will allow saving time on looking into PgBoss code, debugging PgBoss code + Sequelize to understand the requirements for executeSql
and how to pass values
from executeSql to Sequelize db via bind
options.