refactor(db): DRY up database layer with shared helpers and lint enforcement#550
Merged
refactor(db): DRY up database layer with shared helpers and lint enforcement#550
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧Coverage
Other
🤖 This preview updates automatically when you update the PR. |
…rcement Add metadata helpers (getMetadata, setMetadata, clearMetadata) and shared touchCacheEntry to src/lib/db/utils.ts, replacing repeated per-file SQL boilerplate across install-info, version-check, release-channel, dsn-cache, project-cache, and project-aliases modules. Key changes: - Batch metadata reads/writes/deletes via IN clauses and transactions - Shared touchCacheEntry eliminates 3 duplicate private functions - Manual BEGIN/COMMIT/ROLLBACK replaced with db.transaction()() - Deduplicated project-cache get/set pairs into getByKey/setByKey helpers - Removed async/Promise from 27 synchronous SQLite functions and ~370 await calls at call sites, narrowing the biome useAwait override to only files with genuinely async operations (stat, clearResponseCache, refreshToken) - 3 GritQL lint rules enforce using helpers over raw SQL patterns - AGENTS.md updated with new helper docs and corrected sync signatures
000e8d9 to
3eec916
Compare
Contributor
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 98.05%. Project has 1036 uncovered lines. Files with missing lines (12)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 96.02% 96.03% +0.01%
==========================================
Files 193 193 —
Lines 26142 26105 -37
Branches 0 0 —
==========================================
+ Hits 25103 25069 -34
- Misses 1039 1036 -3
- Partials 0 0 —Generated by Codecov Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DRY up the
src/lib/db/layer by extracting shared helpers, removing duplicated SQL patterns, and adding GritQL lint rules to prevent regression.Changes
New helpers in
src/lib/db/utils.tsgetMetadata(db, keys)— batch read from metadata table (SELECT ... WHERE key IN (...))setMetadata(db, entries)— batch write in a single transactionclearMetadata(db, keys)— batch delete (DELETE ... WHERE key IN (...))touchCacheEntry(table, keyColumn, keyValue)— sharedlast_accessedtimestamp updateRefactored DB modules
install-info.ts— 4 individual queries → 1 batch call per operationversion-check.ts,release-channel.ts— same metadata helper adoptiondsn-cache.ts,project-cache.ts— privatetouchCacheEntry→ shared helperproject-cache.ts— deduplicated 4 get/set functions viagetByKey/setByKeyhelpersproject-aliases.ts— manualBEGIN/COMMIT/ROLLBACK→db.transaction()()De-async synchronous functions
Removed
async/Promise<>from 27 DB functions that only do synchronous SQLite operations, plus ~370awaitremovals at call sites. Narrowed the biomeuseAwait: "off"override to only files with genuinely async operations.GritQL lint rules (3 new)
no-raw-metadata-queries.grit— enforcesgetMetadata/setMetadata/clearMetadatano-manual-transactions.grit— enforcesdb.transaction()()no-inline-touch-cache.grit— enforces sharedtouchCacheEntry()Documentation