Complete the code to import the connection pool module.
const { Pool } = require('[1]');The pg module is used for PostgreSQL connection pooling in Node.js.
Complete the code to create a new connection pool with a max of 10 connections.
const pool = new Pool({ max: [1] });The max option sets the maximum number of connections in the pool. Here, it is set to 10.
Fix the error in releasing the client back to the pool.
client.[1]();To return a client to the pool, you must call release(). Other methods close or end the connection permanently.
Fill both blanks to query the database and release the client properly.
pool.connect().then(client => {
return client.query([1])
.then(res => {
client.[2]();
return res;
});
});The query string should be a SELECT statement to fetch data. The client must be released with release() after the query.
Fill all three blanks to create a pool, query data, and handle errors properly.
const pool = new Pool({ max: [1] });
async function fetchData() {
const client = await pool.connect();
try {
const result = await client.query([2]);
return result.rows;
} catch (err) {
console.error([3]);
} finally {
client.release();
}
}The pool max connections is set to 10. The query fetches all products. Errors are logged using the caught error variable err.