File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ type InsertStatement interface {
1515 OverridingUserValue ()
1616 DefaultValues ()
1717 Value (value ... any )
18- Values (values ... any )
18+ Values (values ... [] any )
1919 Select (f func (b SelectStatement ))
2020
2121 OnConflict (f func (b ConflictTarget )) ConflictAction
@@ -89,9 +89,9 @@ func (st *insertStmt) Value(value ...any) {
8989 st .values .push (& x )
9090}
9191
92- func (st * insertStmt ) Values (values ... any ) {
92+ func (st * insertStmt ) Values (values ... [] any ) {
9393 for _ , value := range values {
94- st .Value (value )
94+ st .Value (value ... )
9595 }
9696}
9797
Original file line number Diff line number Diff line change @@ -171,4 +171,31 @@ func TestInsert(t *testing.T) {
171171 args ,
172172 )
173173 })
174+
175+ t .Run ("values" , func (t * testing.T ) {
176+ q , args := pgstmt .Insert (func (b pgstmt.InsertStatement ) {
177+ b .Into ("users" )
178+ b .Columns ("username" , "name" )
179+ b .Values ([][]any {
180+ {"tester1" , "Tester 1" },
181+ {"tester2" , "Tester 2" },
182+ }... )
183+ }).SQL ()
184+
185+ assert .Equal (t ,
186+ stripSpace (`
187+ insert into users (username, name)
188+ values ($1, $2),
189+ ($3, $4)
190+ ` ),
191+ q ,
192+ )
193+ assert .EqualValues (t ,
194+ []any {
195+ "tester1" , "Tester 1" ,
196+ "tester2" , "Tester 2" ,
197+ },
198+ args ,
199+ )
200+ })
174201}
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ type Distinct interface {
5555
5656type Values interface {
5757 Value (value ... any )
58- Values (values ... any )
58+ Values (values ... [] any )
5959}
6060
6161type OrderBy interface {
@@ -425,9 +425,9 @@ func (st *values) Value(value ...any) {
425425 st .push (& x )
426426}
427427
428- func (st * values ) Values (values ... any ) {
428+ func (st * values ) Values (values ... [] any ) {
429429 for _ , value := range values {
430- st .Value (value )
430+ st .Value (value ... )
431431 }
432432}
433433
You can’t perform that action at this time.
0 commit comments