Skip to content

Commit

Permalink
Add um.Set() method that takes a slice of expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo committed Jan 2, 2024
1 parent 07da5c0 commit ed4d0c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dialect/mysql/um/qm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/clause"
"github.com/stephenafamo/bob/dialect/mysql/dialect"
"github.com/stephenafamo/bob/internal"
"github.com/stephenafamo/bob/mods"
)

Expand Down Expand Up @@ -51,6 +52,12 @@ func StraightJoin(e any) bob.Mod[*dialect.UpdateQuery] {
return dialect.StraightJoin[*dialect.UpdateQuery](e)
}

func Set(sets ...bob.Expression) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.Set.Set = append(q.Set.Set, internal.ToAnySlice(sets)...)
})
}

func SetCol(from ...string) mods.Set[*dialect.UpdateQuery] {
return mods.Set[*dialect.UpdateQuery](from)
}
Expand Down
7 changes: 7 additions & 0 deletions dialect/psql/um/qm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/clause"
"github.com/stephenafamo/bob/dialect/psql/dialect"
"github.com/stephenafamo/bob/internal"
"github.com/stephenafamo/bob/mods"
)

Expand Down Expand Up @@ -38,6 +39,12 @@ func TableAs(name any, alias string) bob.Mod[*dialect.UpdateQuery] {
})
}

func Set(sets ...bob.Expression) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.Set.Set = append(q.Set.Set, internal.ToAnySlice(sets)...)
})
}

func SetCol(from string) mods.Set[*dialect.UpdateQuery] {
return mods.Set[*dialect.UpdateQuery]([]string{from})
}
Expand Down
7 changes: 7 additions & 0 deletions dialect/sqlite/um/qm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package um
import (
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/dialect/sqlite/dialect"
"github.com/stephenafamo/bob/internal"
"github.com/stephenafamo/bob/mods"
)

Expand Down Expand Up @@ -60,6 +61,12 @@ func TableNotIndexed() bob.Mod[*dialect.UpdateQuery] {
})
}

func Set(sets ...bob.Expression) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.Set.Set = append(q.Set.Set, internal.ToAnySlice(sets)...)
})
}

func SetCol(from string) mods.Set[*dialect.UpdateQuery] {
return mods.Set[*dialect.UpdateQuery]([]string{from})
}
Expand Down

0 comments on commit ed4d0c1

Please sign in to comment.