CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/sqlite-go-best-practices

SQLite best practices for Go — WAL mode, foreign_keys, busy_timeout, SetMaxOpenConns, context-aware queries, transactions, migrations

98

2.36x
Quality

99%

Does it follow best practices?

Impact

97%

2.36x

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 applies SQLite best practices (WAL mode, foreign_keys ON, busy_timeout, SetMaxOpenConns(1), modernc.org/sqlite, context-aware queries, proper transactions, defer rows.Close, rows.Err check) when building a simple note-taking app. The task never mentions any of these practices -- it only describes business requirements.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "modernc.org/sqlite driver",
      "description": "Uses modernc.org/sqlite (pure Go driver) rather than mattn/go-sqlite3 (CGO). The import should be _ \"modernc.org/sqlite\" and the driver name should be \"sqlite\".",
      "max_score": 8
    },
    {
      "name": "WAL mode enabled",
      "description": "WAL journal mode is set via connection string pragma (_pragma=journal_mode(WAL)) or by executing PRAGMA journal_mode=WAL right after opening the database",
      "max_score": 10
    },
    {
      "name": "foreign_keys enabled via DSN",
      "description": "Foreign key enforcement is enabled via the connection string (_pragma=foreign_keys(ON)) so it applies to every connection the pool creates, not set once after sql.Open",
      "max_score": 10
    },
    {
      "name": "busy_timeout set",
      "description": "A busy_timeout pragma is configured (e.g., _pragma=busy_timeout(5000)) to handle lock contention gracefully",
      "max_score": 8
    },
    {
      "name": "SetMaxOpenConns(1)",
      "description": "db.SetMaxOpenConns(1) is called to serialize SQLite access and prevent 'database is locked' errors. This is the most critical SQLite-specific setting in Go.",
      "max_score": 12
    },
    {
      "name": "Context-aware queries used",
      "description": "Code uses QueryContext, QueryRowContext, ExecContext, and/or BeginTx instead of the non-context variants (Query, QueryRow, Exec, Begin)",
      "max_score": 10
    },
    {
      "name": "defer rows.Close() on all queries",
      "description": "Every call to QueryContext (or Query) is followed by defer rows.Close() to prevent connection leaks",
      "max_score": 8
    },
    {
      "name": "rows.Err() checked after iteration",
      "description": "After iterating over rows with rows.Next(), the code checks rows.Err() to detect errors that may have terminated iteration early",
      "max_score": 6
    },
    {
      "name": "Parameterized queries throughout",
      "description": "ALL queries use ? placeholders with separate parameters -- no string interpolation (fmt.Sprintf) or concatenation to build SQL strings",
      "max_score": 10
    },
    {
      "name": "Transaction for note+tag creation",
      "description": "Creating a note with tags uses a transaction (BeginTx) to ensure atomicity -- either the note and all tag links are created, or none are",
      "max_score": 8
    },
    {
      "name": "defer tx.Rollback() pattern",
      "description": "Transactions use defer tx.Rollback() immediately after BeginTx to guarantee rollback on any error path",
      "max_score": 5
    },
    {
      "name": "Migration with version tracking",
      "description": "Database schema is set up via a migration pattern with version tracking (a _migrations table or similar), not just raw CREATE TABLE statements",
      "max_score": 5
    }
  ]
}

evals

tile.json