CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/postgresql-node-best-practices

PostgreSQL patterns for Node.js with pg — connection pooling, parameterized

99

1.75x
Quality

99%

Does it follow best practices?

Impact

100%

1.75x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-1/

Analytics Dashboard Backend

Problem/Feature Description

A fintech company needs a backend service for their analytics dashboard. The service is built with Node.js, TypeScript, and Express, querying a PostgreSQL database via the pg package. The database runs on AWS RDS and is accessible via a DATABASE_URL environment variable. The service will be deployed to production on ECS behind an ALB.

The dashboard needs to support:

  • Getting a summary of total revenue (stored as NUMERIC(15,2)) and total transaction count (stored as BIGINT) for a given date range
  • Listing the top N customers by total spend, returning customer ID (BIGINT), name, and total_spent (NUMERIC)
  • Getting daily revenue breakdown for a date range, returning date, transaction_count (BIGINT), and daily_revenue (NUMERIC)
  • Filtering transactions by multiple status values (e.g. "completed", "pending", "refunded") passed as an array

Existing tables (already created, no migrations needed):

  • transactions: id (bigint), customer_id (bigint), amount_cents (numeric(15,2)), status (text), created_at (timestamptz)
  • customers: id (bigint), name (text), email (text)

Output Specification

Produce:

  • db.ts -- Database connection module
  • analytics.ts -- Functions for all four dashboard queries
  • package.json -- With required dependencies

The code should be complete TypeScript with no placeholders or TODO comments.

evals

scenario-1

criteria.json

task.md

tile.json