Skip to content

Commit

Permalink
fix pg module import (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzuo authored Jan 28, 2024
1 parent 10a41b9 commit ee3dbd3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions generator/client/typescript/templates/queryx/adapter.postgresql.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Code generated by queryx, DO NOT EDIT.

import { Pool, QueryResultRow, types } from "pg";
import pg from "pg";
import { parse } from "date-fns";
import { Config } from "./config";

types.setTypeParser(types.builtins.INT8, (val) => parseInt(val, 10));
pg.types.setTypeParser(pg.types.builtins.INT8, (val) => parseInt(val, 10));

export class Adapter {
public config: Config;
public pool: Pool;
public db: Pool;
public pool?: pg.Pool;
public db?: pg.Pool;

constructor(config: Config) {
this.config = config;
}

connect() {
const pool = new Pool({
const pool = new pg.Pool({
connectionString: this.config.url,
});
this.pool = pool;
Expand All @@ -31,20 +31,23 @@ export class Adapter {
this.db.release();
}

private _query<R extends QueryResultRow = any, I extends any[] = any[]>(
private _query<R extends pg.QueryResultRow = any, I extends any[] = any[]>(
query: string,
args?: I,
) {
let [query1, args1] = rebind<I>(query, args);
return this.db.query<R, I>(query1, args1);
}

async query<R extends QueryResultRow = any>(query: string, ...args: any[]) {
async query<R extends pg.QueryResultRow = any>(
query: string,
...args: any[]
) {
const res = await this._query<R>(query, args);
return res.rows;
}

async queryOne<R extends QueryResultRow = any>(
async queryOne<R extends pg.QueryResultRow = any>(
query: string,
...args: any[]
) {
Expand Down

0 comments on commit ee3dbd3

Please sign in to comment.