Skip to content

Commit

Permalink
reuse pool connection when creating transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzuo committed Sep 1, 2024
1 parent daceaa1 commit f69465d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 17 deletions.
6 changes: 0 additions & 6 deletions generator/client/typescript/templates/queryx/adapter.mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Config } from "./config";

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

constructor(config: Config) {
Expand All @@ -17,14 +16,9 @@ export class Adapter {
const pool = mysql.createPool({
uri: this.config.url,
});
this.pool = pool;
this.db = pool;
}

newClient() {
return this.pool.getConnection();
}

release() {
this.db.release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pg.types.setTypeParser(pg.types.builtins.INT8, (val) => parseInt(val, 10));

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

constructor(config: Config) {
Expand All @@ -19,14 +18,9 @@ export class Adapter {
const pool = new pg.Pool({
connectionString: this.config.url,
});
this.pool = pool;
this.db = pool;
}

newClient() {
return this.pool.connect();
}

release() {
this.db.release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export class Adapter {
this.db = new Database(this.config.url);
}

newClient() {
return new Database(this.config.url);
}

release() {}

query<R>(query: string, ...args: any[]): R[] {
Expand Down
2 changes: 1 addition & 1 deletion generator/client/typescript/templates/queryx/client.tstmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class QXClient {

async tx() {
const tx = new Tx(this.config);
tx.adapter.db = await this.adapter.newClient();
tx.adapter.db = await this.adapter.db;
await tx.adapter.beginTx();
return tx;
}
Expand Down

0 comments on commit f69465d

Please sign in to comment.