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

{
  "context": "Tests transactional booking with capacity validation (read capacity + create booking must be atomic to prevent overbooking), money handling (ticket prices as cents), date/time storage, enum constraints on status columns, and FK indexing. The task describes business rules but never prescribes implementation patterns.",
  "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": "Atomic booking with capacity check",
      "description": "Booking seats uses db.transaction() that reads remaining capacity AND creates the booking atomically, preventing overbooking race conditions",
      "max_score": 16
    },
    {
      "name": "Cancel booking in transaction",
      "description": "Cancelling a booking (status update + capacity release) uses db.transaction()",
      "max_score": 8
    },
    {
      "name": "Indexes on bookings.event_id FK",
      "description": "Explicit CREATE INDEX on the bookings foreign key column referencing events",
      "max_score": 8
    },
    {
      "name": "Prepared statements throughout",
      "description": "All queries use db.prepare() with ? placeholders",
      "max_score": 10
    },
    {
      "name": "Money as INTEGER cents",
      "description": "Ticket price and total cost stored as INTEGER (cents), not REAL",
      "max_score": 7
    },
    {
      "name": "CHECK constraints on statuses",
      "description": "Both event status and booking status columns have CHECK constraints",
      "max_score": 6
    },
    {
      "name": "Dates as TEXT ISO 8601",
      "description": "Event dates and timestamps stored as TEXT, queries use datetime() functions",
      "max_score": 5
    },
    {
      "name": "Migration pattern",
      "description": "Sequential migration pattern with tracking table",
      "max_score": 5
    },
    {
      "name": "STRICT tables",
      "description": "Tables created with STRICT keyword",
      "max_score": 4
    },
    {
      "name": "synchronous = NORMAL",
      "description": "PRAGMA synchronous = NORMAL is set",
      "max_score": 3
    }
  ]
}

evals

tile.json