Skip to content

Commit

Permalink
Use client instead of size 1 pool (#7182)
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored May 15, 2024
1 parent feca439 commit fec7acb
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 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 pool: pg.Pool;
let client: pg.Client;
switch (user.type) {
case "CLOUD_IAM_USER": {
connector = new Connector({
Expand All @@ -43,11 +43,10 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
pool = new pg.Pool({
client = new pg.Client({
...clientOpts,
user: opts.username,
database: opts.databaseId,
max: 1,
});
break;
}
Expand All @@ -61,11 +60,10 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
pool = new pg.Pool({
client = new pg.Client({
...clientOpts,
user: opts.username,
database: opts.databaseId,
max: 1,
});
break;
}
Expand All @@ -81,12 +79,11 @@ export async function execute(
instanceConnectionName: connectionName,
ipType: IpAddressTypes.PUBLIC,
});
pool = new pg.Pool({
client = new pg.Client({
...clientOpts,
user: opts.username,
password: opts.password,
database: opts.databaseId,
max: 1,
});
break;
}
Expand All @@ -96,13 +93,13 @@ export async function execute(
for (const s of sqlStatements) {
logFn(`Executing: '${s}'`);
try {
await pool.query(s);
await client.query(s);
} catch (err) {
throw new FirebaseError(`Error executing ${err}`);
}
}

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

Expand Down

0 comments on commit fec7acb

Please sign in to comment.