diff --git a/pgstmt/insert.go b/pgstmt/insert.go index e60a377..86a3dd2 100644 --- a/pgstmt/insert.go +++ b/pgstmt/insert.go @@ -15,7 +15,7 @@ type InsertStatement interface { OverridingUserValue() DefaultValues() Value(value ...any) - Values(values ...any) + Values(values ...[]any) Select(f func(b SelectStatement)) OnConflict(f func(b ConflictTarget)) ConflictAction @@ -89,9 +89,9 @@ func (st *insertStmt) Value(value ...any) { st.values.push(&x) } -func (st *insertStmt) Values(values ...any) { +func (st *insertStmt) Values(values ...[]any) { for _, value := range values { - st.Value(value) + st.Value(value...) } } diff --git a/pgstmt/insert_test.go b/pgstmt/insert_test.go index eb5b24b..56a979f 100644 --- a/pgstmt/insert_test.go +++ b/pgstmt/insert_test.go @@ -171,4 +171,31 @@ func TestInsert(t *testing.T) { args, ) }) + + t.Run("values", func(t *testing.T) { + q, args := pgstmt.Insert(func(b pgstmt.InsertStatement) { + b.Into("users") + b.Columns("username", "name") + b.Values([][]any{ + {"tester1", "Tester 1"}, + {"tester2", "Tester 2"}, + }...) + }).SQL() + + assert.Equal(t, + stripSpace(` + insert into users (username, name) + values ($1, $2), + ($3, $4) + `), + q, + ) + assert.EqualValues(t, + []any{ + "tester1", "Tester 1", + "tester2", "Tester 2", + }, + args, + ) + }) } diff --git a/pgstmt/select.go b/pgstmt/select.go index e47b69e..65b9cbf 100644 --- a/pgstmt/select.go +++ b/pgstmt/select.go @@ -55,7 +55,7 @@ type Distinct interface { type Values interface { Value(value ...any) - Values(values ...any) + Values(values ...[]any) } type OrderBy interface { @@ -425,9 +425,9 @@ func (st *values) Value(value ...any) { st.push(&x) } -func (st *values) Values(values ...any) { +func (st *values) Values(values ...[]any) { for _, value := range values { - st.Value(value) + st.Value(value...) } }