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

criteria.jsonevals/scenario-4/

{
  "context": "Tests whether the agent proactively uses unnest for bulk inserts, ANY($1::type[]) for array filtering, proper pool configuration, and parameterized queries when building a catalog service. The task never mentions these patterns -- it only describes business requirements.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "Pool with production settings",
      "description": "db.ts creates a pg Pool with max connections, at least one timeout setting (idleTimeoutMillis, connectionTimeoutMillis, or statement_timeout), and keepAlive: true",
      "max_score": 8
    },
    {
      "name": "Parameterized queries throughout",
      "description": "ALL query functions use $1, $2 placeholders with values in a separate array -- no string interpolation or concatenation of variables into SQL strings",
      "max_score": 12
    },
    {
      "name": "Bulk import uses unnest or multi-row VALUES",
      "description": "The batch import function inserts all products in a single query using unnest(...) with parallel typed arrays, or a multi-row VALUES clause -- NOT a loop of individual INSERT statements",
      "max_score": 18
    },
    {
      "name": "No loop of individual INSERTs for batch",
      "description": "The batch import does NOT iterate over products with a for/forEach loop calling an INSERT for each individual row",
      "max_score": 12
    },
    {
      "name": "Typed array casts on unnest or parameters",
      "description": "Array parameters in the bulk insert include PostgreSQL type casts (e.g. unnest($1::text[]), unnest($2::int[]))",
      "max_score": 8
    },
    {
      "name": "ANY for tag filtering",
      "description": "Finding products by tags uses the && (overlap) operator with a typed array parameter (e.g. tags && $1::text[]) or ANY -- NOT a dynamically constructed IN clause",
      "max_score": 10
    },
    {
      "name": "ANY for multi-category filter",
      "description": "Finding products in multiple categories uses ANY($1::text[]) with a single array parameter -- NOT dynamically building IN ($1, $2, $3...) placeholders",
      "max_score": 10
    },
    {
      "name": "RETURNING clause on INSERT",
      "description": "The single product INSERT uses RETURNING * (or RETURNING with columns) to get back the created row",
      "max_score": 7
    },
    {
      "name": "pool.query for single queries",
      "description": "Non-transactional query functions use pool.query() directly rather than pool.connect()/client.query()",
      "max_score": 7
    },
    {
      "name": "Pool error handler",
      "description": "pool.on('error', ...) is registered",
      "max_score": 4
    },
    {
      "name": "Graceful shutdown",
      "description": "pool.end() is called on SIGTERM/SIGINT",
      "max_score": 4
    }
  ]
}

evals

tile.json