or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Connection Lifecycle Manager

A database utility that manages PostgreSQL connections with automatic connection recycling based on usage limits.

Capabilities

Pool Configuration

  • Creates a connection pool with a maximum of 5 connections @test
  • Configures the pool to recycle connections after 10 uses @test
  • Sets idle timeout to 5000 milliseconds @test

Connection Usage Tracking

  • Tracks connection usage count across multiple queries @test
  • Automatically retires a connection after it reaches the usage limit @test
  • Creates a new connection when retired connection is removed from pool @test

Query Execution

  • Executes queries using pooled connections @test
  • Returns query results correctly @test

Pool Cleanup

  • Gracefully shuts down the pool and all connections @test

Implementation

@generates

API

/**
 * Creates and configures a connection pool with connection recycling.
 *
 * @param {Object} config - Database configuration object
 * @param {string} config.host - Database host
 * @param {number} config.port - Database port
 * @param {string} config.database - Database name
 * @param {string} config.user - Database user
 * @param {string} config.password - Database password
 * @returns {Object} Configured pool instance
 */
function createPool(config) {
  // IMPLEMENTATION HERE
}

/**
 * Executes a query using a connection from the pool.
 *
 * @param {Object} pool - The pool instance
 * @param {string} text - SQL query text
 * @param {Array} [values] - Query parameters
 * @returns {Promise<Object>} Query result
 */
async function executeQuery(pool, text, values) {
  // IMPLEMENTATION HERE
}

/**
 * Closes the pool and all connections.
 *
 * @param {Object} pool - The pool instance
 * @returns {Promise<void>}
 */
async function closePool(pool) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createPool,
  executeQuery,
  closePool
};

Dependencies { .dependencies }

pg { .dependency }

Provides PostgreSQL database connectivity and connection pooling support.