Skip to content

Comments

refactor: Code simplification and helper extraction#14

Merged
josemarluedke merged 3 commits intomainfrom
refactor/code-simplification
Dec 15, 2025
Merged

refactor: Code simplification and helper extraction#14
josemarluedke merged 3 commits intomainfrom
refactor/code-simplification

Conversation

@josemarluedke
Copy link
Member

Summary

This PR simplifies the codebase by extracting helpers, eliminating duplication, and improving readability. All changes are non-breaking and preserve existing functionality.

Changes

1. File Organization

  • Split models.go into page_args.go and page_info.go for better organization
  • Added NewEmptyPageInfo() constructor for convenient empty PageInfo creation

2. Helper Extraction

cursor/paginator.go

  • Extracted parsePageArgs() helper to consolidate duplicate validation logic
  • Both New() and BuildFetchParams() now share this code
  • Removed dead code: unused defaultOrderBy and buildOrderBy() function
  • Saved: ~50 lines

cursor/schema.go

  • Extracted fixedFieldsToSorts() helper method
  • Eliminated repeated fieldSpec-to-Sort conversion code
  • Saved: ~25 lines

quotafill/quotafill.go

  • Extracted argsForEncoder() and getSortBy() helpers
  • Eliminated 4 instances of duplicated cursor args building
  • Saved: ~30 lines

3. Code Simplification

offset/cursor.go

  • Simplified DecodeCursor() with early return pattern
  • Clearer control flow, removed unnecessary variable pre-declarations

sqlboiler/cursor.go

  • Consolidated pass-through switch cases
  • Reduced: 15 lines → 3 lines

4. Test Coverage

  • Added comprehensive test for NewEmptyPageInfo()
  • Verifies all fields return correct nil/false values

Impact

  • Net reduction: ~50 lines of code (108 insertions, 186 deletions)
  • All tests passing: 175/175 specs (added 1 new test)
  • No breaking changes: All public APIs preserved
  • No behavior changes: Functionality remains identical
  • Improved maintainability: Less duplication, clearer code organization

Commits

  1. feat(core): add NewEmptyPageInfo and refactor file organization
  2. refactor: extract helpers and simplify code across packages
  3. test(core): add test coverage for NewEmptyPageInfo

🤖 Generated with Claude Code

josemarluedke and others added 3 commits December 15, 2025 09:13
Added NewEmptyPageInfo() constructor to provide a convenient way to
create empty PageInfo instances for error cases and empty result sets.

Also refactored by splitting models.go into page_args.go and page_info.go
to improve code organization and make components easier to locate.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Extracted helper functions to eliminate duplication and improve readability:

- cursor/paginator.go: Extracted parsePageArgs helper to consolidate
  common parameter parsing logic used by New() and BuildFetchParams()
- cursor/schema.go: Extracted fixedFieldsToSorts helper to eliminate
  repeated Sort conversion logic
- quotafill/quotafill.go: Extracted argsForEncoder and getSortBy helpers
  to remove duplicated encoder argument construction
- offset/cursor.go: Simplified DecodeCursor with early returns for better
  control flow
- sqlboiler/cursor.go: Consolidated type switch cases to reduce verbosity

These changes reduce complexity and improve maintainability without
changing any functionality. All tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added comprehensive test to verify NewEmptyPageInfo returns correct
nil/false values for all PageInfo fields (TotalCount, StartCursor,
EndCursor, HasNextPage, HasPreviousPage).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@josemarluedke josemarluedke added the Type: Enhancement New feature or request label Dec 15, 2025
@josemarluedke josemarluedke merged commit ed13646 into main Dec 15, 2025
1 of 2 checks passed
@josemarluedke josemarluedke deleted the refactor/code-simplification branch December 15, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant