0
0
NextJSframework~10 mins

Connection pooling for serverless in NextJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the database client for connection pooling.

NextJS
import { [1] } from '@vercel/postgres';
Drag options to blanks, or click blank then click option'
Apool
BcreateClient
Cconnect
DClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createClient' instead of 'pool' causes no pooling.
Using 'connect' is incorrect as it's not exported here.
2fill in blank
medium

Complete the code to acquire a client connection from the pool.

NextJS
const client = await pool.[1]();
Drag options to blanks, or click blank then click option'
Aconnect
BgetClient
Cacquire
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getClient' or 'acquire' causes runtime errors as these methods don't exist.
3fill in blank
hard

Fix the error in releasing the client connection back to the pool.

NextJS
await client.[1]();
Drag options to blanks, or click blank then click option'
Aclose
Brelease
Cend
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'close' or 'end' closes the connection permanently, breaking pooling.
4fill in blank
hard

Fill both blanks to create a query and release the client properly.

NextJS
const result = await client.[1]('SELECT NOW()');
await client.[2]();
Drag options to blanks, or click blank then click option'
Aquery
Brelease
Cexecute
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' instead of 'query' causes errors.
Using 'close' instead of 'release' breaks pooling.
5fill in blank
hard

Fill all three blanks to implement a safe query with try-finally for connection pooling.

NextJS
const client = await pool.[1]();
try {
  const result = await client.[2]('SELECT * FROM users');
  return result.rows;
} finally {
  await client.[3]();
}
Drag options to blanks, or click blank then click option'
Aconnect
Bquery
Crelease
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to release client causes connection leaks.
Using 'close' instead of 'release' breaks pooling.