refactor: add getAffectedRows() helper to eliminate result extraction branching#2374
refactor: add getAffectedRows() helper to eliminate result extraction branching#2374
Conversation
… branching Adds BaseRepository.getAffectedRows(result) that normalizes affected row counts across SQLite (.changes), PostgreSQL (.rowCount), and MySQL ([0].affectedRows). Replaces 3-way branching in: - misc.ts: clearPacketLogs, cleanupOldPacketLogs - auth.ts: deactivateApiToken, revokeAllUserApiTokens - messages.ts: insertMessage Auth methods also simplified from 3 typed-db paths to single this.db path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: getAffectedRows() Helper ImplementationReview Checklist:
Overall AssessmentThis PR successfully introduces a clean abstraction for extracting affected row counts across database backends. The implementation is solid and the code reduction is meaningful (net -57 lines). Code Quality Review✅ Helper Method Implementation (
|
Summary
Phase 2 of the Drizzle refactor — adds
BaseRepository.getAffectedRows(result)helper that normalizes affected row counts across all three database backends.The helper
Methods simplified
misc.tsclearPacketLogsmisc.tscleanupOldPacketLogsauth.tsdeactivateApiTokenthis.dbpath (10 lines)auth.tsrevokeAllUserApiTokensthis.dbpath (10 lines)messages.tsinsertMessageNot changed (yet)
notifications.tsmethods use a different pattern where MySQL results are already destructured from the tuple. These need a different approach and are deferred.Files Changed
src/db/repositories/base.tsgetAffectedRows()helpersrc/db/repositories/misc.tssrc/db/repositories/auth.tssrc/db/repositories/messages.tsTest plan
🤖 Generated with Claude Code