Skip to content

Commit

Permalink
Switch back to pg.Pool (#7198)
Browse files Browse the repository at this point in the history
* switch back to pg.Pool

* m

* m

---------

Co-authored-by: joehan <joehanley@google.com>
  • Loading branch information
fredzqm and joehan committed May 21, 2024
1 parent 134d94a commit dda60a1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/gcp/cloudsql/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function execute(
);
}
let connector: Connector;
let client: pg.Client;
let pool: pg.Pool;
switch (user.type) {
case "CLOUD_IAM_USER": {
connector = new Connector({
Expand All @@ -43,7 +43,7 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
database: opts.databaseId,
Expand All @@ -60,7 +60,7 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
database: opts.databaseId,
Expand All @@ -79,7 +79,7 @@ export async function execute(
instanceConnectionName: connectionName,
ipType: IpAddressTypes.PUBLIC,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
password: opts.password,
Expand All @@ -89,17 +89,19 @@ export async function execute(
}
}

const conn = await pool.connect();
logFn(`Logged in as ${opts.username}`);
for (const s of sqlStatements) {
logFn(`Executing: '${s}'`);
try {
await client.query(s);
await conn.query(s);
} catch (err) {
throw new FirebaseError(`Error executing ${err}`);
}
}

await client.end();
conn.release();
await pool.end();
connector.close();
}

Expand Down

0 comments on commit dda60a1

Please sign in to comment.