-
Notifications
You must be signed in to change notification settings - Fork 1
perf: Optimize SQL string construction #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4676819
perf: Optimize SQL string construction
google-labs-jules[bot] 0e75480
feat: Apply multiple performance improvements
google-labs-jules[bot] 886bbd4
feat: Apply multiple performance improvements
google-labs-jules[bot] 768dc1d
Update queryset.go
emicklei 412bcde
Update queryset.go
emicklei a78a365
Update mutationset.go
emicklei b7c31fa
Update queryset.go
emicklei 20fd9a4
Update queryset.go
emicklei c3c0a13
Update mutationset.go
emicklei eba53b0
Update queryset.go
emicklei 5421ad5
Update mutationset.go
emicklei bfa5135
Update mutationset.go
emicklei 8d341fa
Update mutationset.go
emicklei 6795614
Update mutationset.go
emicklei 2f5230f
fix llm garbage
emicklei c3d28f8
Merge branch 'main' into perf/optimize-sql-building
emicklei ccb2107
add iterator test
emicklei 2c565d4
add badges
emicklei dfbd099
add badges fix
emicklei 99d23be
upload codecov
emicklei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package pgtalk | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/jackc/pgx/v5" | ||
| "github.com/jackc/pgx/v5/pgconn" | ||
| ) | ||
|
|
||
| func TestResultIterator_Next(t *testing.T) { | ||
| t.Run("happy flow", func(t *testing.T) { | ||
| rows := &mockRows{ | ||
| nextResult: true, | ||
| scanError: nil, | ||
| closeCalled: false, | ||
| } | ||
| selectors := []ColumnAccessor{ | ||
| mockColumnAccessor{ | ||
| fieldValueToScan: func(entity any) any { | ||
| return &entity.(*testEntity).ID | ||
| }, | ||
| }, | ||
| } | ||
| i := &resultIterator[testEntity]{ | ||
| rows: rows, | ||
| orderedSelectors: selectors, | ||
| } | ||
| if !i.HasNext() { | ||
| t.Fatal("expected next") | ||
| } | ||
| entity, err := i.Next() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if entity.ID != "test-id" { | ||
| t.Errorf("expected test-id, got %s", entity.ID) | ||
| } | ||
| if i.HasNext() { | ||
| t.Fatal("unexpected next") | ||
| } | ||
| if !rows.closeCalled { | ||
| t.Error("expected close to be called") | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestResultIterator_Err(t *testing.T) { | ||
| t.Run("query error", func(t *testing.T) { | ||
| i := &resultIterator[testEntity]{ | ||
| queryError: errors.New("query error"), | ||
| } | ||
| if err := i.Err(); err == nil || err.Error() != "query error" { | ||
| t.Errorf("expected query error, got %v", err) | ||
| } | ||
| }) | ||
| t.Run("rows error", func(t *testing.T) { | ||
| rows := &mockRows{ | ||
| err: errors.New("rows error"), | ||
| } | ||
| i := &resultIterator[testEntity]{ | ||
| rows: rows, | ||
| } | ||
| if err := i.Err(); err == nil || err.Error() != "rows error" { | ||
| t.Errorf("expected rows error, got %v", err) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestResultIterator_GetParams(t *testing.T) { | ||
| params := []any{"param1", 2} | ||
| i := &resultIterator[testEntity]{ | ||
| params: params, | ||
| } | ||
| p := i.GetParams() | ||
| if len(p) != 2 { | ||
| t.Errorf("expected 2 params, got %d", len(p)) | ||
| } | ||
| if p[1] != "param1" { | ||
| t.Errorf("expected param1, got %v", p[1]) | ||
| } | ||
| if p[2] != 2 { | ||
| t.Errorf("expected 2, got %v", p[2]) | ||
| } | ||
| } | ||
|
|
||
| // mockColumnAccessor is a mock for the ColumnAccessor interface | ||
| type mockColumnAccessor struct { | ||
| fieldValueToScan func(entity any) any | ||
| } | ||
|
|
||
| func (m mockColumnAccessor) SQLOn(w WriteContext) {} | ||
| func (m mockColumnAccessor) Name() string { return "" } | ||
| func (m mockColumnAccessor) ValueToInsert() any { return nil } | ||
| func (m mockColumnAccessor) Column() ColumnInfo { return ColumnInfo{} } | ||
| func (m mockColumnAccessor) FieldValueToScan(entity any) any { return m.fieldValueToScan(entity) } | ||
| func (m mockColumnAccessor) AppendScannable(list []any) []any { return list } | ||
| func (m mockColumnAccessor) Get(values map[string]any) any { return nil } | ||
| func (m mockColumnAccessor) SetSource(parameterIndex int) string { return "" } | ||
|
|
||
| // mockRows is a mock for the pgx.Rows interface | ||
| type mockRows struct { | ||
| nextResult bool | ||
| scanError error | ||
| closeCalled bool | ||
| err error | ||
| } | ||
|
|
||
| func (m *mockRows) Close() { m.closeCalled = true } | ||
| func (m *mockRows) Err() error { return m.err } | ||
| func (m *mockRows) CommandTag() pgconn.CommandTag { return pgconn.CommandTag{} } | ||
| func (m *mockRows) FieldDescriptions() []pgconn.FieldDescription { return nil } | ||
| func (m *mockRows) Next() bool { return m.nextResult } | ||
| func (m *mockRows) Scan(dest ...any) error { | ||
| if m.scanError != nil { | ||
| return m.scanError | ||
| } | ||
| // simulate scanning a value | ||
| if len(dest) > 0 { | ||
| if id, ok := dest[0].(*string); ok { | ||
| *id = "test-id" | ||
| } | ||
| } | ||
| m.nextResult = false // only one row | ||
| return nil | ||
| } | ||
| func (m *mockRows) RawValues() [][]byte { return nil } | ||
| func (m *mockRows) Conn() *pgx.Conn { return nil } | ||
| func (m *mockRows) Values() ([]any, error) { return nil, nil } | ||
|
|
||
| // testEntity is a simple struct for testing | ||
| type testEntity struct { | ||
| ID string | ||
| } |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.