Skip to content

Commit 09c8491

Browse files
committed
minor refactor
1 parent a365b5a commit 09c8491

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

dialect/mysql/load.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func Preload[T any, Ts ~[]T](rel orm.Relationship, cols []string, opts ...Preloa
6767
var queryMods mods.QueryMods[*dialect.SelectQuery]
6868

6969
for i, side := range rel.Sides {
70-
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
71-
if settings.Alias != "" {
72-
alias = settings.Alias
70+
alias = settings.Alias
71+
if settings.Alias == "" {
72+
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
7373
}
7474
on := make([]bob.Expression, 0, len(side.FromColumns)+len(side.FromWhere)+len(side.ToWhere))
7575
for i, fromCol := range side.FromColumns {

dialect/mysql/view.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ func (v *View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, queryM
8585

8686
// Prepare a statement from an existing query that will be mapped to the view's type
8787
func (v *View[T, Tslice]) PrepareQuery(ctx context.Context, exec bob.Preparer, q bob.Query) (bob.QueryStmt[T, Tslice], error) {
88-
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, v.scanner, v.afterSelect(ctx, exec))
88+
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, v.scanner, v.afterSelect(exec))
8989
}
9090

91-
func (v *View[T, Ts]) afterSelect(ctx context.Context, exec bob.Executor) bob.ExecOption[T] {
91+
func (v *View[T, Ts]) afterSelect(exec bob.Executor) bob.ExecOption[T] {
9292
return func(es *bob.ExecSettings[T]) {
9393
es.AfterSelect = func(ctx context.Context, retrieved []T) error {
9494
_, err := v.AfterSelectHooks.Do(ctx, exec, retrieved)
@@ -154,23 +154,23 @@ func (v *ViewQuery[T, Tslice]) One() (T, error) {
154154
if err := v.hook(); err != nil {
155155
return *new(T), err
156156
}
157-
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
157+
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
158158
}
159159

160160
// All matching rows
161161
func (v *ViewQuery[T, Tslice]) All() (Tslice, error) {
162162
if err := v.hook(); err != nil {
163163
return nil, err
164164
}
165-
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
165+
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
166166
}
167167

168168
// Cursor to scan through the results
169169
func (v *ViewQuery[T, Tslice]) Cursor() (scan.ICursor[T], error) {
170170
if err := v.hook(); err != nil {
171171
return nil, err
172172
}
173-
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
173+
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
174174
}
175175

176176
// Count the number of matching rows

dialect/psql/load.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func Preload[T any, Ts ~[]T](rel orm.Relationship, cols []string, opts ...Preloa
6767
var queryMods mods.QueryMods[*dialect.SelectQuery]
6868

6969
for i, side := range rel.Sides {
70-
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
71-
if settings.Alias != "" {
72-
alias = settings.Alias
70+
alias = settings.Alias
71+
if settings.Alias == "" {
72+
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
7373
}
7474
on := make([]bob.Expression, 0, len(side.FromColumns)+len(side.FromWhere)+len(side.ToWhere))
7575
for i, fromCol := range side.FromColumns {

dialect/psql/table.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func (t *TableQuery[Q, T, Ts]) addReturning() {
357357
}
358358
}
359359

360-
func (t *TableQuery[Q, T, Ts]) afterSelect(ctx context.Context, exec bob.Executor) bob.ExecOption[T] {
360+
func (t *TableQuery[Q, T, Ts]) afterSelect(exec bob.Executor) bob.ExecOption[T] {
361361
return func(es *bob.ExecSettings[T]) {
362362
es.AfterSelect = func(ctx context.Context, retrieved []T) error {
363363
_, err := t.view.AfterSelectHooks.Do(ctx, exec, retrieved)
@@ -390,7 +390,7 @@ func (t *TableQuery[Q, T, Tslice]) One() (T, error) {
390390
if err := t.hook(); err != nil {
391391
return *new(T), err
392392
}
393-
return bob.One(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
393+
return bob.One(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
394394
}
395395

396396
// All matching rows
@@ -399,7 +399,7 @@ func (t *TableQuery[Q, T, Tslice]) All() (Tslice, error) {
399399
if err := t.hook(); err != nil {
400400
return nil, err
401401
}
402-
return bob.Allx[T, Tslice](t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
402+
return bob.Allx[T, Tslice](t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
403403
}
404404

405405
// Cursor to scan through the results
@@ -408,5 +408,5 @@ func (t *TableQuery[Q, T, Tslice]) Cursor() (scan.ICursor[T], error) {
408408
if err := t.hook(); err != nil {
409409
return nil, err
410410
}
411-
return bob.Cursor(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
411+
return bob.Cursor(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
412412
}

dialect/psql/view.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ func (v *View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, queryM
104104

105105
// Prepare a statement from an existing query that will be mapped to the view's type
106106
func (v *View[T, Tslice]) PrepareQuery(ctx context.Context, exec bob.Preparer, q bob.Query) (bob.QueryStmt[T, Tslice], error) {
107-
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, v.scanner, v.afterSelect(ctx, exec))
107+
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, v.scanner, v.afterSelect(exec))
108108
}
109109

110-
func (v *View[T, Ts]) afterSelect(ctx context.Context, exec bob.Executor) bob.ExecOption[T] {
110+
func (v *View[T, Ts]) afterSelect(exec bob.Executor) bob.ExecOption[T] {
111111
return func(es *bob.ExecSettings[T]) {
112112
es.AfterSelect = func(ctx context.Context, retrieved []T) error {
113113
_, err := v.AfterSelectHooks.Do(ctx, exec, retrieved)
@@ -173,23 +173,23 @@ func (v *ViewQuery[T, Tslice]) One() (T, error) {
173173
if err := v.hook(); err != nil {
174174
return *new(T), err
175175
}
176-
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
176+
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
177177
}
178178

179179
// All matching rows
180180
func (v *ViewQuery[T, Tslice]) All() (Tslice, error) {
181181
if err := v.hook(); err != nil {
182182
return nil, err
183183
}
184-
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
184+
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
185185
}
186186

187187
// Cursor to scan through the results
188188
func (v *ViewQuery[T, Tslice]) Cursor() (scan.ICursor[T], error) {
189189
if err := v.hook(); err != nil {
190190
return nil, err
191191
}
192-
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
192+
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
193193
}
194194

195195
// Count the number of matching rows

dialect/sqlite/load.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func Preload[T any, Ts ~[]T](rel orm.Relationship, cols []string, opts ...Preloa
6767
var queryMods mods.QueryMods[*dialect.SelectQuery]
6868

6969
for i, side := range rel.Sides {
70-
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
71-
if settings.Alias != "" {
72-
alias = settings.Alias
70+
alias = settings.Alias
71+
if settings.Alias == "" {
72+
alias = fmt.Sprintf("%s_%d", side.To, internal.RandInt())
7373
}
7474
on := make([]bob.Expression, 0, len(side.FromColumns)+len(side.FromWhere)+len(side.ToWhere))
7575
for i, fromCol := range side.FromColumns {

dialect/sqlite/table.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (t *TQuery[Q, T, Ts]) addReturning() {
360360
}
361361
}
362362

363-
func (t *TQuery[Q, T, Ts]) afterSelect(ctx context.Context, exec bob.Executor) bob.ExecOption[T] {
363+
func (t *TQuery[Q, T, Ts]) afterSelect(exec bob.Executor) bob.ExecOption[T] {
364364
return func(es *bob.ExecSettings[T]) {
365365
es.AfterSelect = func(ctx context.Context, retrieved []T) error {
366366
_, err := t.view.AfterSelectHooks.Do(ctx, exec, retrieved)
@@ -393,7 +393,7 @@ func (t *TQuery[Q, T, Tslice]) One() (T, error) {
393393
if err := t.hook(); err != nil {
394394
return *new(T), err
395395
}
396-
return bob.One(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
396+
return bob.One(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
397397
}
398398

399399
// All matching rows
@@ -402,7 +402,7 @@ func (t *TQuery[Q, T, Tslice]) All() (Tslice, error) {
402402
if err := t.hook(); err != nil {
403403
return nil, err
404404
}
405-
return bob.Allx[T, Tslice](t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
405+
return bob.Allx[T, Tslice](t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
406406
}
407407

408408
// Cursor to scan through the results
@@ -411,5 +411,5 @@ func (t *TQuery[Q, T, Tslice]) Cursor() (scan.ICursor[T], error) {
411411
if err := t.hook(); err != nil {
412412
return nil, err
413413
}
414-
return bob.Cursor(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.ctx, t.exec))
414+
return bob.Cursor(t.ctx, t.exec, t, t.view.scanner, t.afterSelect(t.exec))
415415
}

dialect/sqlite/view.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ func (v *View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, queryM
104104

105105
// Prepare a statement from an existing query that will be mapped to the view's type
106106
func (v *View[T, Tslice]) PrepareQuery(ctx context.Context, exec bob.Preparer, q bob.Query) (bob.QueryStmt[T, Tslice], error) {
107-
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, scan.StructMapper[T](), v.afterSelect(ctx, exec))
107+
return bob.PrepareQueryx[T, Tslice](ctx, exec, q, scan.StructMapper[T](), v.afterSelect(exec))
108108
}
109109

110-
func (v *View[T, Ts]) afterSelect(ctx context.Context, exec bob.Executor) bob.ExecOption[T] {
110+
func (v *View[T, Ts]) afterSelect(exec bob.Executor) bob.ExecOption[T] {
111111
return func(es *bob.ExecSettings[T]) {
112112
es.AfterSelect = func(ctx context.Context, retrieved []T) error {
113113
_, err := v.AfterSelectHooks.Do(ctx, exec, retrieved)
@@ -173,23 +173,23 @@ func (v *ViewQuery[T, Tslice]) One() (T, error) {
173173
if err := v.hook(); err != nil {
174174
return *new(T), err
175175
}
176-
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
176+
return bob.One(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
177177
}
178178

179179
// All matching rows
180180
func (v *ViewQuery[T, Tslice]) All() (Tslice, error) {
181181
if err := v.hook(); err != nil {
182182
return nil, err
183183
}
184-
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
184+
return bob.Allx[T, Tslice](v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
185185
}
186186

187187
// Cursor to scan through the results
188188
func (v *ViewQuery[T, Tslice]) Cursor() (scan.ICursor[T], error) {
189189
if err := v.hook(); err != nil {
190190
return nil, err
191191
}
192-
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.ctx, v.exec))
192+
return bob.Cursor(v.ctx, v.exec, v, v.view.scanner, v.view.afterSelect(v.exec))
193193
}
194194

195195
// Count the number of matching rows

0 commit comments

Comments
 (0)