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-9/

User Profile Query System

Build a simple user profile query system that safely retrieves user information from a PostgreSQL database using parameterized queries.

Requirements

Create a module that provides functions to query user profiles from a database. The system should support:

  1. Retrieving a user by their ID
  2. Finding users by email address
  3. Searching for users by age range (minimum and maximum age)

All database queries must use proper parameterization to prevent SQL injection vulnerabilities. Assume the database has a users table with columns: id, email, age, and registration_date.

Implementation

@generates

API

/**
 * Retrieves a user profile by user ID
 *
 * @param {Object} client - Database client instance
 * @param {number} userId - The user's ID
 * @returns {Promise<Object|null>} User object or null if not found
 */
async function getUserById(client, userId) {
  // IMPLEMENTATION HERE
}

/**
 * Finds a user by email address
 *
 * @param {Object} client - Database client instance
 * @param {string} email - The user's email address
 * @returns {Promise<Object|null>} User object or null if not found
 */
async function getUserByEmail(client, email) {
  // IMPLEMENTATION HERE
}

/**
 * Finds all users within a specified age range
 *
 * @param {Object} client - Database client instance
 * @param {number} minAge - Minimum age (inclusive)
 * @param {number} maxAge - Maximum age (inclusive)
 * @returns {Promise<Array>} Array of user objects
 */
async function getUsersByAgeRange(client, minAge, maxAge) {
  // IMPLEMENTATION HERE
}

module.exports = {
  getUserById,
  getUserByEmail,
  getUsersByAgeRange
};

Test Cases

The following test cases verify the functionality:

  • Given a valid user ID, getUserById returns the correct user object @test
  • Given an invalid user ID, getUserById returns null @test
  • Given a valid email address, getUserByEmail returns the correct user @test
  • Given an age range of 25-35, getUsersByAgeRange returns all users within that range @test

Dependencies { .dependencies }

pg-native { .dependency }

Provides PostgreSQL database connectivity and query execution.

Install with Tessl CLI

npx tessl i tessl/npm-pg-native

tile.json