or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Query Result Formatter

A utility module that executes PostgreSQL queries and formats the results based on user preferences.

Capabilities

Execute queries with object row format

The module should execute a SQL query and return results where each row is represented as an object with column names as keys.

  • Given a query "SELECT id, name FROM users WHERE id = $1" with value [1], executing with object format returns a result where the first row has properties id and name accessible by their column names @test

Execute queries with array row format

The module should execute a SQL query and return results where each row is represented as an array of values in column order.

  • Given a query "SELECT id, name, email FROM users WHERE id = $1" with value [2], executing with array format returns a result where the first row is an array with three elements in the order [id_value, name_value, email_value] @test

Handle multiple rows in different formats

The module should correctly handle queries that return multiple rows, respecting the chosen format.

  • Given a query "SELECT id, status FROM orders WHERE user_id = $1" with value [100] that returns 3 rows, executing with array format returns 3 arrays where each array has 2 elements @test
  • Given a query "SELECT id, status FROM orders WHERE user_id = $1" with value [100] that returns 3 rows, executing with object format returns 3 objects where each object has id and status properties @test

Implementation

@generates

API

/**
 * Executes a query with object row format (default PostgreSQL behavior).
 * Returns results where each row is an object with column names as keys.
 *
 * @param {Object} client - Connected PostgreSQL client
 * @param {string} query - SQL query string
 * @param {Array} values - Parameter values for the query
 * @returns {Promise<Object>} Query result with rows as objects
 */
async function executeWithObjectFormat(client, query, values) {
  // IMPLEMENTATION HERE
}

/**
 * Executes a query with array row format.
 * Returns results where each row is an array of values in column order.
 *
 * @param {Object} client - Connected PostgreSQL client
 * @param {string} query - SQL query string
 * @param {Array} values - Parameter values for the query
 * @returns {Promise<Object>} Query result with rows as arrays
 */
async function executeWithArrayFormat(client, query, values) {
  // IMPLEMENTATION HERE
}

module.exports = {
  executeWithObjectFormat,
  executeWithArrayFormat,
};

Dependencies { .dependencies }

pg { .dependency }

Provides PostgreSQL client functionality for Node.js, including support for configuring row result formats.

@satisfied-by