remove postgres connection pooling
This commit is contained in:
parent
62f2cff42e
commit
4bab24f1ac
|
@ -14,6 +14,7 @@ module PgMock {
|
|||
function Client() {}
|
||||
|
||||
Client.prototype.query = query
|
||||
Client.prototype.end = jest.fn()
|
||||
Client.prototype.connect = jest.fn()
|
||||
Client.prototype.release = jest.fn()
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
import { DatasourcePlus } from "./base/datasourcePlus"
|
||||
|
||||
module PostgresModule {
|
||||
const { Pool } = require("pg")
|
||||
const { Client } = require("pg")
|
||||
const Sql = require("./base/sql")
|
||||
const { escapeDangerousCharacters } = require("../utilities")
|
||||
|
||||
|
@ -104,7 +104,6 @@ module PostgresModule {
|
|||
}
|
||||
|
||||
class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||
static pool: any
|
||||
private readonly client: any
|
||||
private readonly config: PostgresConfig
|
||||
private index: number = 1
|
||||
|
@ -136,11 +135,7 @@ module PostgresModule {
|
|||
}
|
||||
: undefined,
|
||||
}
|
||||
if (!this.pool) {
|
||||
this.pool = new Pool(newConfig)
|
||||
}
|
||||
|
||||
this.client = this.pool
|
||||
this.client = new Client(newConfig)
|
||||
this.setSchema()
|
||||
}
|
||||
|
||||
|
@ -171,16 +166,17 @@ module PostgresModule {
|
|||
} catch (err) {
|
||||
// @ts-ignore
|
||||
throw new Error(err)
|
||||
} finally {
|
||||
await this.client.end()
|
||||
}
|
||||
}
|
||||
|
||||
setSchema() {
|
||||
async setSchema() {
|
||||
await this.client.connect()
|
||||
if (!this.config.schema) {
|
||||
this.config.schema = "public"
|
||||
}
|
||||
this.client.on("connect", (client: any) => {
|
||||
client.query(`SET search_path TO ${this.config.schema}`)
|
||||
})
|
||||
this.client.query(`SET search_path TO ${this.config.schema}`)
|
||||
this.COLUMNS_SQL = `select * from information_schema.columns where table_schema = '${this.config.schema}'`
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,6 @@ describe("Postgres Integration", () => {
|
|||
config = new TestConfiguration()
|
||||
})
|
||||
|
||||
it("calls the connection callback", async () => {
|
||||
expect(pg.on).toHaveBeenCalledWith('connect', expect.anything())
|
||||
})
|
||||
|
||||
it("calls the create method with the correct params", async () => {
|
||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||
await config.integration.create({
|
||||
|
|
Loading…
Reference in New Issue