CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/sqlite-node-best-practices

SQLite best practices for Node.js with better-sqlite3 — WAL mode, pragmas, foreign keys, STRICT tables, transactions, migrations, graceful shutdown, and query patterns

97

1.65x
Quality

98%

Does it follow best practices?

Impact

96%

1.65x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

criteria.jsonevals/scenario-4/

{
  "context": "Tests transactional integrity patterns. The task requires atomic multi-item operations (receive shipment, record sale) with validation — this must use db.transaction(). Stock movements reference products (FK indexing). Date range queries test proper TEXT/ISO date storage. The task never mentions transactions, pragmas, or indexes.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "WAL mode enabled",
      "description": "db.ts sets PRAGMA journal_mode = WAL",
      "max_score": 8
    },
    {
      "name": "Foreign keys ON",
      "description": "db.ts sets PRAGMA foreign_keys = ON",
      "max_score": 8
    },
    {
      "name": "Busy timeout set",
      "description": "db.ts sets PRAGMA busy_timeout to a positive value",
      "max_score": 6
    },
    {
      "name": "Graceful shutdown",
      "description": "db.close() called on SIGTERM/SIGINT",
      "max_score": 6
    },
    {
      "name": "Receive shipment uses transaction",
      "description": "Receiving a shipment (multi-item stock update + movement records) is wrapped in db.transaction() for atomic commit/rollback",
      "max_score": 14
    },
    {
      "name": "Record sale uses transaction with validation",
      "description": "Recording a sale checks stock levels and updates quantities within a db.transaction(), rolling back if any item has insufficient stock (throw inside transaction)",
      "max_score": 14
    },
    {
      "name": "Indexes on FK columns",
      "description": "Explicit CREATE INDEX on stock_movements.product_id (or equivalent FK column)",
      "max_score": 8
    },
    {
      "name": "Prepared statements throughout",
      "description": "All queries use db.prepare() with ? placeholders",
      "max_score": 10
    },
    {
      "name": "Money as INTEGER cents",
      "description": "Unit cost and sell price stored as INTEGER (cents), not REAL",
      "max_score": 6
    },
    {
      "name": "Dates as TEXT for movement timestamps",
      "description": "Timestamps stored as TEXT ISO 8601, date range queries use datetime() functions",
      "max_score": 6
    },
    {
      "name": "CHECK constraint on movement type",
      "description": "Movement type column uses CHECK constraint for valid values",
      "max_score": 4
    },
    {
      "name": "Migration pattern",
      "description": "Sequential migration pattern with tracking table",
      "max_score": 5
    },
    {
      "name": "STRICT tables",
      "description": "Tables created with STRICT keyword",
      "max_score": 5
    }
  ]
}

evals

tile.json