Skip to content
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

Rename Setter method from Insert to InsertMod #142

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dialect/mysql/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Execut

if t.unretrievable {
for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}
_, err = q.Exec(ctx, exec)
if err != nil {
Expand All @@ -179,7 +179,7 @@ func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Execut
inserted := make(Tslice, len(rows))
for i, row := range rows {
q.Expression.Values.Vals = nil
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
result, err := q.Exec(ctx, exec)
if err != nil {
return nil, err
Expand Down Expand Up @@ -292,7 +292,7 @@ func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Execut

if t.unretrievable {
for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}

_, err = q.Exec(ctx, exec)
Expand All @@ -306,7 +306,7 @@ func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Execut
upserted := make(Tslice, len(rows))
for i, row := range rows {
q.Expression.Values.Vals = nil
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
result, err := q.Exec(ctx, exec)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions dialect/psql/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Execut
)

for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}

ctx, err = t.InsertQueryHooks.Do(ctx, exec, q.Expression)
Expand Down Expand Up @@ -222,7 +222,7 @@ func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Execut
)

for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}

ctx, err = t.InsertQueryHooks.Do(ctx, exec, q.Expression)
Expand Down
4 changes: 2 additions & 2 deletions dialect/sqlite/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Execut
)

for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}

ctx, err = t.InsertQueryHooks.Do(ctx, exec, q.Expression)
Expand Down Expand Up @@ -221,7 +221,7 @@ func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Execut
)

for _, row := range rows {
row.Insert().Apply(q.Expression)
row.InsertMod().Apply(q.Expression)
}

ctx, err = t.InsertQueryHooks.Do(ctx, exec, q.Expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var (
{{$.Importer.Import (printf "github.com/stephenafamo/bob/dialect/%s/im" $.Dialect)}}
{{$table := .Table}}
{{$tAlias := .Aliases.Table $table.Key -}}
func (s {{$tAlias.UpSingular}}Setter) Insert() bob.Mod[*dialect.InsertQuery] {
func (s {{$tAlias.UpSingular}}Setter) InsertMod() bob.Mod[*dialect.InsertQuery] {
vals := make([]bob.Expression, 0, {{len $table.NonGeneratedColumns}})
{{range $column := $table.NonGeneratedColumns -}}
{{$colAlias := $tAlias.Column $column.Name -}}
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/models/01_types.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s {{$tAlias.UpSingular}}Setter) Overwrite(t *{{$tAlias.UpSingular}}) {
{{$.Importer.Import (printf "github.com/stephenafamo/bob/dialect/%s/im" $.Dialect)}}
{{$table := .Table}}
{{$tAlias := .Aliases.Table $table.Key -}}
func (s {{$tAlias.UpSingular}}Setter) Insert() bob.Mod[*dialect.InsertQuery] {
func (s {{$tAlias.UpSingular}}Setter) InsertMod() bob.Mod[*dialect.InsertQuery] {
vals := make([]bob.Expression, {{len $table.NonGeneratedColumns}})
{{range $index, $column := $table.NonGeneratedColumns -}}
{{$colAlias := $tAlias.Column $column.Name -}}
Expand Down
2 changes: 1 addition & 1 deletion orm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ type Setter[T any, InsertQ any, UpdateQ any] interface {
// Act as a mod for the update query
bob.Mod[UpdateQ]
// Return a mod for the insert query
Insert() bob.Mod[InsertQ]
InsertMod() bob.Mod[InsertQ]
}