SQLite best practices for Node.js with better-sqlite3 — WAL mode, pragmas, foreign keys, STRICT tables, transactions, migrations, graceful shutdown, and query patterns
97
98%
Does it follow best practices?
Impact
96%
1.65xAverage score across 5 eval scenarios
Passed
No known issues
{
"context": "Tests many-to-many relationship handling (posts-tags junction table needs FK indexes on both columns), JSON column usage (metadata), transactional create (post + tag associations), and slug-based lookups. The task describes only business requirements.",
"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": 5
},
{
"name": "Graceful shutdown",
"description": "db.close() called on SIGTERM/SIGINT",
"max_score": 5
},
{
"name": "Transaction for post+tags creation",
"description": "Creating a post with its tag associations uses db.transaction() for atomicity",
"max_score": 12
},
{
"name": "Indexes on junction table FKs",
"description": "The post_tags junction table has indexes on BOTH post_id and tag_id columns",
"max_score": 12
},
{
"name": "Index on posts.author_id FK",
"description": "posts.author_id (or equivalent) has an explicit index",
"max_score": 6
},
{
"name": "JSON for metadata",
"description": "Post metadata stored as TEXT/JSON column, using json_extract or JSON functions for access",
"max_score": 7
},
{
"name": "CHECK constraint on post status",
"description": "Status column has CHECK (status IN ('draft', 'published', 'archived'))",
"max_score": 5
},
{
"name": "Prepared statements throughout",
"description": "All queries use db.prepare() with ? placeholders",
"max_score": 10
},
{
"name": "Migration pattern",
"description": "Sequential migration pattern with tracking table",
"max_score": 6
},
{
"name": "Dates as TEXT ISO 8601",
"description": "Published date and timestamps stored as TEXT with datetime() defaults",
"max_score": 5
},
{
"name": "STRICT tables",
"description": "Tables created with STRICT keyword",
"max_score": 5
},
{
"name": "Cached prepared statements",
"description": "Frequently used queries (get by slug, list published) are prepared once at module level and reused",
"max_score": 6
}
]
}