-
Notifications
You must be signed in to change notification settings - Fork 1
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
dbConn() creates a new connection pool each time it's called #1
Comments
jedwards1211
added a commit
to jedwards1211/umzug-postgres-storage
that referenced
this issue
Jan 6, 2019
Closed
actually I see that you're ending each pool you use...it seems pointless to use a pool every time, why not just create a |
Here is how I adapted it for my own code, using modern ES: import { Client } from 'pg'
export default class UmzugPostgresStorage {
constructor(config) {
if (config.storageOptions) {
config = config.storageOptions
}
//establish the dbconnection and store in a promise.
this.config = config
}
async query(sql) {
const client = new Client(this.config.database)
try {
await client.connect()
await client.query(`
CREATE TABLE IF NOT EXISTS ${this.config.relation} (
"${this.config.column}" character varying(255)
);
`)
return await client.query(sql)
} finally {
await client.end()
}
}
async logMigration(migrationName) {
await this.query(`
INSERT INTO ${this.config.relation}
("${this.config.column}")
SELECT '${migrationName}'
WHERE NOT EXISTS (
SELECT "${this.config.column}" FROM ${this.config.relation}
WHERE "${this.config.column}" = '${migrationName}'
);
`)
}
async unlogMigration(migrationName) {
await this.query(`
DELETE FROM ${this.config.relation}
WHERE "${this.config.column}" = '${migrationName}'
`)
}
async executed() {
const { rows } = await this.query(`
SELECT "${this.config.column}"
FROM ${this.config.relation}
ORDER BY "${this.config.column}" ASC;
`)
return rows.map(row => row[this.config.column])
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you meant for it to only create one connection pool.
The text was updated successfully, but these errors were encountered: