Skip to content

refactor: extract helpers, constants, and idiomatic patterns#25

Merged
lostmygithubaccount merged 3 commits intomainfrom
cody/code-quality
Apr 5, 2026
Merged

refactor: extract helpers, constants, and idiomatic patterns#25
lostmygithubaccount merged 3 commits intomainfrom
cody/code-quality

Conversation

@lostmygithubaccount
Copy link
Copy Markdown
Member

Summary

  • Extract handle_response<T> / handle_response_unit helpers in dkdc-db-client, eliminating 8 repeated success/error check blocks
  • Extract db_not_found() helper in manager.rs replacing 5 identical Error::Schema(format!(...)) calls
  • Extract enable_wal() helper and WAL_MODE_PRAGMA/WAL_MODE_VALUE constants in db.rs, deduplicating WAL init in open_with_config and open_in_memory
  • Extract DEFAULT_SCHEMA constant in catalog.rs for the "public" schema name
  • Use IN_MEMORY_PATH constant in db.rs (manager.rs already had one)
  • Fix indexed loop for i in 0..10 { REGIONS[i] } to idiomatic for (i, name) in REGIONS.iter().enumerate() in benchmark

No functional changes. All 167 tests pass, clippy clean, fmt clean.

🤖 Generated with Claude Code

lostmygithubaccount and others added 3 commits April 5, 2026 10:51
Replace repeated magic strings/numbers with named constants:
- DEFAULT_HOST, DEFAULT_PORT, DEFAULT_SERVER_URL in dkdc-db-core (shared)
- IN_MEMORY_PATH in manager.rs (crate-local)
- DEFAULT_LOG_LINES in cli.rs (crate-local)
- Reuse api::MAX_BODY_SIZE in server lib.rs instead of duplicating 16*1024*1024

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Quote table names in SQL queries to prevent SQL injection
- Validate table names against actual table list before use in SQL
- Add single-quote escaping to escape_html to prevent XSS
- Validate database exists in onboarding_create_table before rendering

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract handle_response/handle_response_unit in client (~100 lines saved)
- Extract db_not_found() helper in manager (6 call sites)
- Extract enable_wal() helper and WAL constants in db.rs
- Extract DEFAULT_SCHEMA constant in catalog.rs
- Use IN_MEMORY_PATH constant in db.rs (manager.rs already had it)
- Fix indexed loop to iterator pattern in benchmark

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lostmygithubaccount lostmygithubaccount enabled auto-merge (squash) April 5, 2026 22:23
@lostmygithubaccount lostmygithubaccount merged commit 5398d77 into main Apr 5, 2026
1 check passed
@lostmygithubaccount lostmygithubaccount deleted the cody/code-quality branch April 5, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant