CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pg-native

A slightly nicer interface to Postgres over node-libpq providing both sync and async operations

88

1.20x

Quality

Pending

Does it follow best practices?

Impact

88%

1.20x

Average score across 10 eval scenarios

Overview
Eval results
Files

task.mdevals/scenario-3/

Database Query Executor

Build a utility module that executes PostgreSQL queries using three different asynchronous patterns. The module should provide wrapper functions that handle callback-based, promise-based, and async/await query execution.

Capabilities

Callback-based Query Execution

Executes a query and returns results via a callback function following Node.js callback convention (error-first callbacks).

  • Given a connected client and query "SELECT 1 as value", executes the query and calls the callback with (null, result) where result contains rows @test
  • Given a connected client and parameterized query with values array, executes the query and calls the callback with the result @test

Promise-based Query Execution

Executes a query and returns a Promise that resolves with the query result.

  • Given a connected client and query, returns a Promise that resolves with the query result object @test
  • When a query fails, returns a Promise that rejects with the error @test

Async/Await Query Execution

Executes a query as an async function that can be awaited.

  • Given a connected client and query, awaiting the function returns the query result @test
  • When a query fails during async execution, throws an error that can be caught with try/catch @test

Implementation

@generates

API

/**
 * Executes a query using callback-based approach
 * @param {Object} client - Database client connection
 * @param {string} query - SQL query string
 * @param {Array} values - Parameter values for the query (optional)
 * @param {Function} callback - Callback function (err, result) => void
 */
function executeWithCallback(client, query, values, callback) {
  // Implementation
}

/**
 * Executes a query using Promise-based approach
 * @param {Object} client - Database client connection
 * @param {string} query - SQL query string
 * @param {Array} values - Parameter values for the query (optional)
 * @returns {Promise} Promise that resolves with query result or rejects with error
 */
function executeWithPromise(client, query, values) {
  // Implementation
}

/**
 * Executes a query using async/await approach
 * @param {Object} client - Database client connection
 * @param {string} query - SQL query string
 * @param {Array} values - Parameter values for the query (optional)
 * @returns {Promise} Promise that resolves with query result
 */
async function executeWithAsync(client, query, values) {
  // Implementation
}

module.exports = {
  executeWithCallback,
  executeWithPromise,
  executeWithAsync
};

Dependencies { .dependencies }

pg-native { .dependency }

Provides native PostgreSQL database client with support for synchronous and asynchronous operations.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-pg-native

tile.json