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

{
  "context": "Tests whether the agent proactively uses proper transaction patterns (BEGIN/COMMIT/ROLLBACK with client.release() in finally), connection pooling with production settings, parameterized queries, error code handling, and proper migration patterns when building an order system. The task describes atomicity as a business requirement but never prescribes HOW to implement it.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "Transaction with BEGIN/COMMIT",
      "description": "The create order function uses explicit BEGIN and COMMIT statements within a transaction",
      "max_score": 12
    },
    {
      "name": "ROLLBACK on error",
      "description": "The transaction catch block issues ROLLBACK before re-throwing the error",
      "max_score": 10
    },
    {
      "name": "client.release() in finally",
      "description": "The transaction client acquired via pool.connect() is released in a finally block -- not in try or catch, but specifically in finally to guarantee release",
      "max_score": 12
    },
    {
      "name": "pool.connect() for transactions",
      "description": "Transactions use pool.connect() to acquire a dedicated client (not pool.query() which auto-releases)",
      "max_score": 8
    },
    {
      "name": "Pool with production settings",
      "description": "db.ts creates a pg Pool with max connections and at least one timeout setting (idleTimeoutMillis, connectionTimeoutMillis, or statement_timeout)",
      "max_score": 8
    },
    {
      "name": "keepAlive enabled",
      "description": "Pool is configured with keepAlive: true",
      "max_score": 5
    },
    {
      "name": "Parameterized queries throughout",
      "description": "ALL queries use $1, $2 placeholders -- no string interpolation or concatenation of variables into SQL",
      "max_score": 12
    },
    {
      "name": "RETURNING clause on INSERT",
      "description": "INSERT queries use RETURNING * or RETURNING with columns to get back created rows",
      "max_score": 5
    },
    {
      "name": "Foreign key constraint handling",
      "description": "Code handles PostgreSQL error code 23503 (foreign_key_violation) when an order references a non-existent menu_item_id, returning a meaningful error",
      "max_score": 8
    },
    {
      "name": "Pool error handler",
      "description": "pool.on('error', ...) is registered to handle unexpected errors",
      "max_score": 5
    },
    {
      "name": "Graceful shutdown",
      "description": "pool.end() is called on SIGTERM/SIGINT",
      "max_score": 5
    },
    {
      "name": "TIMESTAMPTZ in migration",
      "description": "Migration uses TIMESTAMPTZ (not TIMESTAMP) for time columns",
      "max_score": 5
    },
    {
      "name": "FK index in migration",
      "description": "Migration creates an index on the order_items.order_id foreign key column",
      "max_score": 5
    }
  ]
}

evals

tile.json