refactor(rain): split query builders and tests into focused files#25
Conversation
Greptile SummaryThis PR refactors the 1 491-line monolithic Key changes:
Confidence Score: 5/5Safe to merge — purely structural refactoring with no behavioral or API changes. All production logic is a verbatim file-level split from the original query.go; no algorithmic changes, no public API changes, and the test suite (including integration and benchmark tests) is confirmed green. The only findings are a duplicate test assertion and missing t.Parallel() calls — both P2 style issues that do not affect correctness or reliability. query_compile_internal_test.go (duplicate ErrNoConnection assertion); query_insert_test.go and query_write_test.go (missing t.Parallel() on top-level tests). Important Files Changed
|
| if err := (&InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}}).Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) { | ||
| t.Fatalf("expected insert scan ErrNoConnection, got %v", err) | ||
| } | ||
|
|
||
| insertNoRunner := &InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}} | ||
| if err := insertNoRunner.Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) { | ||
| t.Fatalf("expected insert returning scan ErrNoConnection, got %v", err) | ||
| } |
There was a problem hiding this comment.
Duplicate
ErrNoConnection assertion for InsertQuery.Scan
Lines 43–45 and 47–50 create an identical InsertQuery (no runner, same table and returning) and both assert that Scan returns ErrNoConnection. The second block is redundant and should be removed.
| if err := (&InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}}).Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) { | |
| t.Fatalf("expected insert scan ErrNoConnection, got %v", err) | |
| } | |
| insertNoRunner := &InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}} | |
| if err := insertNoRunner.Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) { | |
| t.Fatalf("expected insert returning scan ErrNoConnection, got %v", err) | |
| } | |
| insertNoRunner := &InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}} | |
| if err := insertNoRunner.Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) { | |
| t.Fatalf("expected insert scan ErrNoConnection, got %v", err) | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/rain/query_compile_internal_test.go
Line: 43-50
Comment:
**Duplicate `ErrNoConnection` assertion for `InsertQuery.Scan`**
Lines 43–45 and 47–50 create an identical `InsertQuery` (no runner, same `table` and `returning`) and both assert that `Scan` returns `ErrNoConnection`. The second block is redundant and should be removed.
```suggestion
insertNoRunner := &InsertQuery{dialect: db.Dialect(), table: users.TableDef(), returning: []schema.Expression{users.ID}}
if err := insertNoRunner.Scan(context.Background(), &internalUserRow{}); !errors.Is(err, ErrNoConnection) {
t.Fatalf("expected insert scan ErrNoConnection, got %v", err)
}
```
How can I resolve this? If you propose a fix, please make it concise.| "github.com/hyperlocalise/rain-orm/pkg/schema" | ||
| ) | ||
|
|
||
| func TestSelectToSQL(t *testing.T) { |
There was a problem hiding this comment.
Missing
t.Parallel() on top-level test functions
TestSelectToSQL (this file, line 13) is missing t.Parallel(). The same pattern applies to several top-level functions in the other new test files: all eight TestInsert* functions in query_insert_test.go, and TestInsertUpdateDeleteToSQL, TestReturningUnsupportedDialect, and TestReturningSupportedOperations in query_write_test.go.
All of these are pure SQL-compilation tests with no shared mutable state, so they are safe to run in parallel. Adding t.Parallel() aligns them with the rest of the suite (e.g. TestExpandedTypesCompileToSQL, TestSelectAdvancedComposition, TestDialectFeatures) and avoids unnecessarily serialising an otherwise parallel test run.
| func TestSelectToSQL(t *testing.T) { | |
| func TestSelectToSQL(t *testing.T) { | |
| t.Parallel() |
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/rain/query_select_test.go
Line: 13
Comment:
**Missing `t.Parallel()` on top-level test functions**
`TestSelectToSQL` (this file, line 13) is missing `t.Parallel()`. The same pattern applies to several top-level functions in the other new test files: all eight `TestInsert*` functions in `query_insert_test.go`, and `TestInsertUpdateDeleteToSQL`, `TestReturningUnsupportedDialect`, and `TestReturningSupportedOperations` in `query_write_test.go`.
All of these are pure SQL-compilation tests with no shared mutable state, so they are safe to run in parallel. Adding `t.Parallel()` aligns them with the rest of the suite (e.g. `TestExpandedTypesCompileToSQL`, `TestSelectAdvancedComposition`, `TestDialectFeatures`) and avoids unnecessarily serialising an otherwise parallel test run.
```suggestion
func TestSelectToSQL(t *testing.T) {
t.Parallel()
```
How can I resolve this? If you propose a fix, please make it concise.
What this PR for?
Refactors the monolithic query builder implementation into focused file-level units for select, insert, update, delete, SQL compilation, and shared helpers, without changing behavior or package boundaries. Also reorganizes the query test suite into matching focused test files while preserving existing assertions and keeping the full fmt, lint, and test suite green.
What did you do for validating the changes?
Anything else you want to add? (Optional)