Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update a few region tags to the correct Cloud SQL version #1560

Merged
merged 3 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions cloud-sql/postgres/knex/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const logger = winston.createLogger({
transports: [new winston.transports.Console(), loggingWinston],
});

// [START cloud_sql_postgres_connection_pool]
// [START cloud_sql_postgres_knex_create]
// Initialize Knex, a Node.js SQL query builder library with built-in connection pooling.
const connect = () => {
// Configure which instance and what database user to connect with.
Expand All @@ -67,43 +67,43 @@ const connect = () => {
// ... Specify additional properties here.
// [START_EXCLUDE]

// [START cloud_sql_limit_connections]
// [START cloud_sql_postgres_knex_limit]
// 'max' limits the total number of concurrent connections this pool will keep. Ideal
// values for this setting are highly variable on app design, infrastructure, and database.
knex.client.pool.max = 5;
// 'min' is the minimum number of idle connections Knex maintains in the pool.
// Additional connections will be established to meet this value unless the pool is full.
knex.client.pool.min = 5;
// [END cloud_sql_limit_connections]
// [START cloud_sql_connection_timeout]
// [END cloud_sql_postgres_knex_limit]
// [START cloud_sql_postgres_knex_timeout]
// 'acquireTimeoutMillis' is the maximum number of milliseconds to wait for a connection checkout.
// Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an
// SQLException.
knex.client.pool.createTimeoutMillis = 30000; // 30 seconds
// 'idleTimeoutMillis' is the maximum amount of time a connection can sit in the pool. Connections that
// sit idle for this many milliseconds are retried if idleTimeoutMillis is exceeded.
knex.client.pool.idleTimeoutMillis = 600000; // 10 minutes
// [END cloud_sql_connection_timeout]
// [START cloud_sql_connection_backoff]
// [END cloud_sql_postgres_knex_timeout]
// [START cloud_sql_postgres_knex_backoff]
// 'createRetryIntervalMillis' is how long to idle after failed connection creation before trying again
knex.client.pool.createRetryIntervalMillis = 200; // 0.2 seconds
// [END cloud_sql_connection_backoff]
// [START cloud_sql_connection_lifetime]
// [END cloud_sql_postgres_knex_backoff]
// [START cloud_sql_postgres_knex_lifetime]
// 'acquireTimeoutMillis' is the maximum possible lifetime of a connection in the pool. Connections that
// live longer than this many milliseconds will be closed and reestablished between uses. This
// value should be several minutes shorter than the database's timeout value to avoid unexpected
// terminations.
knex.client.pool.acquireTimeoutMillis = 600000; // 10 minutes
// [START cloud_sql_connection_lifetime]
// [START cloud_sql_postgres_knex_lifetime]

// [END_EXCLUDE]
return knex;
};

const knex = connect();
// [END cloud_sql_postgres_connection_pool]
// [END cloud_sql_postgres_knex_create]

// [START cloud_sql_example_statement]
// [START cloud_sql_postgres_knex_connection]
/**
* Insert a vote record into the database.
*
Expand All @@ -118,7 +118,7 @@ const insertVote = async (knex, vote) => {
throw Error(err);
}
};
// [END cloud_sql_example_statement]
// [END cloud_sql_postgres_knex_connection]

/**
* Retrieve the latest 5 vote records from the database.
Expand Down Expand Up @@ -188,7 +188,6 @@ app.get('/', (req, res) => {
});

app.post('/', async (req, res) => {
// [START cloud_sql_example_statement]
// Get the team from the request and record the time of the vote.
const {team} = req.body;
const timestamp = new Date();
Expand Down