From 6341026f31a750692cce4439204ffbbb420e0c69 Mon Sep 17 00:00:00 2001 From: Stephen Afam-Osemene Date: Tue, 2 Jan 2024 20:00:59 +0000 Subject: [PATCH] Add um.Set() method that takes a slice of expressions --- dialect/mysql/um/qm.go | 7 +++++++ dialect/psql/um/qm.go | 6 ++++++ dialect/sqlite/um/qm.go | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/dialect/mysql/um/qm.go b/dialect/mysql/um/qm.go index 089e14bb..48b674ef 100644 --- a/dialect/mysql/um/qm.go +++ b/dialect/mysql/um/qm.go @@ -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" ) @@ -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) } diff --git a/dialect/psql/um/qm.go b/dialect/psql/um/qm.go index eef79723..8cd1ae9f 100644 --- a/dialect/psql/um/qm.go +++ b/dialect/psql/um/qm.go @@ -38,6 +38,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}) } diff --git a/dialect/sqlite/um/qm.go b/dialect/sqlite/um/qm.go index a82e2846..c66a1531 100644 --- a/dialect/sqlite/um/qm.go +++ b/dialect/sqlite/um/qm.go @@ -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" ) @@ -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}) }