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