PostgreSQL knex connection

Insert data by using the Node.js knex module to manage opening and closing a connection to Cloud SQL for PostgreSQL.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


 * Insert a vote record into the database.
 * @param {object} pool The Knex connection object.
 * @param {object} vote The vote record to insert.
 * @returns {Promise}
const insertVote = async (pool, vote) => {
  try {
    return await pool('votes').insert(vote);
  } catch (err) {
    throw Error(err);

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser