Skip to content

Commit

Permalink
switch back to pg.Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzqm committed May 21, 2024
1 parent fcc84ce commit ea68811
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 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,8 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
client = new pg.Client({
console.log("CLOUD_IAM_SERVICE_ACCOUNT", user, "clientOpts", clientOpts);
pool = new pg.Pool({
...clientOpts,
user: opts.username,
database: opts.databaseId,
Expand All @@ -79,7 +80,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,6 +90,7 @@ export async function execute(
}
}

const client = await pool.connect();
logFn(`Logged in as ${opts.username}`);
for (const s of sqlStatements) {
logFn(`Executing: '${s}'`);
Expand All @@ -99,7 +101,8 @@ export async function execute(
}
}

await client.end();
// This hangs somehow.
// await pool.end();
connector.close();
}

Expand Down

0 comments on commit ea68811

Please sign in to comment.