Skip to content

Conversation

@chandrabistaiah
Copy link

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@chandrabistaiah chandrabistaiah requested review from a team as code owners December 10, 2025 01:01
@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: appengine Issues related to the App Engine Admin API API. asset: pattern DEE Asset tagging - Pattern. labels Dec 10, 2025
@google-cla
Copy link

google-cla bot commented Dec 10, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chandrabistaiah, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the Cloud SQL samples for App Engine, providing clearer distinctions and dedicated examples for both flexible and standard environments. It introduces new standard environment samples for MySQL and PostgreSQL, including basic and connection-pooling implementations, and updates existing flexible environment samples. The changes also involve upgrading the Node.js runtime to version 10 in standard environment configurations and updating CI build settings to accommodate the new sample structure.

Highlights

  • Sample Restructuring: Existing Cloud SQL samples for App Engine have been reorganized and renamed to clearly differentiate between 'flexible' and 'standard' environments for both MySQL and PostgreSQL.
  • New Standard Environment Samples: New samples have been introduced for the App Engine standard environment, demonstrating basic Cloud SQL connectivity and connection pooling for both MySQL and PostgreSQL databases.
  • Runtime Upgrade: The app.yaml configurations for the new standard environment samples, and updated existing ones, now specify nodejs10 as the runtime, moving away from nodejs8.
  • CI Configuration Updates: Kokoro CI configuration files have been updated to reflect the new directory structure and include build configurations for all the newly added standard environment samples across different Node.js versions (node10, node6, node8).
  • Simplified Cloud SQL Connection: The beta_settings.cloud_sql_instances configuration has been removed from app.yaml files in the standard environment samples, indicating a streamlined approach to Cloud SQL instance connection naming.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Cloud SQL samples for App Engine, splitting them by environment (standard/flexible) and database type (MySQL/PostgreSQL), and adding examples for connection pooling. The changes are well-structured. However, I've found some critical issues in the new sample code, such as database connection leaks and improper error handling that could crash the server. I've also suggested updates for outdated dependencies and fixed some typos in the documentation. Please review my comments for details.

Comment on lines +42 to +55
app.get(`/`, (req, res, next) => {
var connection = mysql.createConnection(dbConfig);
connection.query(
`SELECT NOW() as now`,
function (error, results, fields) {
if (error) throw error;
var now = results[0].now;
res
.status(200)
.send(`Current time: ${now}`)
.end();
}
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This request handler has two critical issues:

  1. Connection Leak: A new database connection is created for each request, but it's never closed. This will lead to connection leaks and can exhaust database resources.
  2. Unhandled Errors: throw error; will crash the Node.js process if the database query fails. In an Express application, you should pass errors to the next() function to be handled by an error-handling middleware.

I've suggested a change that fixes both of these issues.

Suggested change
app.get(`/`, (req, res, next) => {
var connection = mysql.createConnection(dbConfig);
connection.query(
`SELECT NOW() as now`,
function (error, results, fields) {
if (error) throw error;
var now = results[0].now;
res
.status(200)
.send(`Current time: ${now}`)
.end();
}
);
});
app.get(`/`, (req, res, next) => {
const connection = mysql.createConnection(dbConfig);
connection.query(
`SELECT NOW() as now`,
(error, results) => {
connection.end();
if (error) {
return next(error);
}
const now = results[0].now;
res.status(200).send(`Current time: ${now}`);
}
);
});

Comment on lines +42 to +57
app.get(`/`, (req, res, next) => {
var client = new pg.Client(dbConfig);
client.connect();
client
.query(`SELECT NOW() as now`)
.then(result => {
var now = result.rows[0].now;
res
.status(200)
.send(`Current time: ${now}`)
.end();
})
.catch(err => {
next(err);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This request handler has two critical issues:

  1. Connection Leak: A new database client is created for each request, but the connection is never closed with client.end(). This will lead to connection leaks and can exhaust database resources.
  2. Unhandled Promise: client.connect() returns a promise that is not handled. While pg might queue the query, it's better practice to ensure the connection is established before querying.

I've suggested a change that uses promise chaining to correctly handle the connection lifecycle and errors.

app.get(`/`, (req, res, next) => {
  const client = new pg.Client(dbConfig);
  client.connect()
    .then(() => client.query(`SELECT NOW() as now`))
    .then(result => {
      const now = result.rows[0].now;
      res.status(200).send(`Current time: ${now}`);
    })
    .catch(err => next(err))
    .then(() => client.end());
});

Comment on lines +47 to +57
pool.query(
`SELECT NOW() as now`,
function (error, results, fields) {
if (error) throw error;
var now = results[0].now;
res
.status(200)
.send(`Current time: ${now}`)
.end();
}
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Unhandled Errors: throw error; will crash the Node.js process if the database query fails. In an Express application, you should pass errors to the next() function so they can be handled properly.

I've suggested a change that fixes this.

  pool.query(
    `SELECT NOW() as now`,
    (error, results) => {
      if (error) {
        return next(error);
      }
      const now = results[0].now;
      res.status(200).send(`Current time: ${now}`);
    }
  );

},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.3.0",
"ava": "0.25.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version of ava is quite old (0.25.0 was released in 2017). Consider upgrading to a more recent version (e.g., ^5.0.0) to take advantage of performance improvements, new features, and bug fixes.

Suggested change
"ava": "0.25.0",
"ava": "^5.0.0",

},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.3.0",
"ava": "0.25.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version of ava is quite old (0.25.0 was released in 2017). Consider upgrading to a more recent version (e.g., ^5.0.0) to take advantage of performance improvements, new features, and bug fixes.

Suggested change
"ava": "0.25.0",
"ava": "^5.0.0",

@@ -0,0 +1,11 @@
# Cloud SQL for PostgreSQL Node.js sample on App Engine standard environment

This sample application shows how to use [Google Cloud SQL[[sql] for [PostgreSQL][postgres]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo here. It should be [Google Cloud SQL][sql] instead of [Google Cloud SQL[[sql].

Suggested change
This sample application shows how to use [Google Cloud SQL[[sql] for [PostgreSQL][postgres]
This sample application shows how to use [Google Cloud SQL][sql] for [PostgreSQL][postgres]

},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.2.1",
"ava": "^0.25.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version of ava is quite old (^0.25.0 was released in 2017). Consider upgrading to a more recent version (e.g., ^5.0.0) to take advantage of performance improvements, new features, and bug fixes.

Suggested change
"ava": "^0.25.0",
"ava": "^5.0.0",

@@ -0,0 +1,11 @@
# Cloud SQL for PostgreSQL Node.js sample on App Engine standard environment

This sample application shows how to use [Google Cloud SQL[[sql] for [PostgreSQL][postgres]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo here. It should be [Google Cloud SQL][sql] instead of [Google Cloud SQL[[sql].

Suggested change
This sample application shows how to use [Google Cloud SQL[[sql] for [PostgreSQL][postgres]
This sample application shows how to use [Google Cloud SQL][sql] for [PostgreSQL][postgres]

},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.2.1",
"ava": "0.25.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version of ava is quite old (0.25.0 was released in 2017). Consider upgrading to a more recent version (e.g., ^5.0.0) to take advantage of performance improvements, new features, and bug fixes.

Suggested change
"ava": "0.25.0",
"ava": "^5.0.0",

@iennae iennae closed this Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: appengine Issues related to the App Engine Admin API API. asset: pattern DEE Asset tagging - Pattern. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants