Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createClient' instead of 'pool' causes no pooling.
Using 'connect' is incorrect as it's not exported here.
✗ Incorrect
The 'pool' export from '@vercel/postgres' is used to manage connection pooling in serverless Next.js apps.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getClient' or 'acquire' causes runtime errors as these methods don't exist.
✗ Incorrect
The 'connect' method is used to get a client connection from the pool.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'close' or 'end' closes the connection permanently, breaking pooling.
✗ Incorrect
The 'release' method returns the client to the pool for reuse.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' instead of 'query' causes errors.
Using 'close' instead of 'release' breaks pooling.
✗ Incorrect
Use 'query' to run SQL and 'release' to return the client to the pool.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to release client causes connection leaks.
Using 'close' instead of 'release' breaks pooling.
✗ Incorrect
Acquire client with 'connect', run query with 'query', and release client with 'release' in finally block.