Skip to content

Commit d60e58c

Browse files
kmpmgeorgysavva
andauthored
Adding ScanAllSets to the api (#115)
* feat: add ScanAllSets * test: mssql for ScanAllSets * fix: ScanOne should close rows * Add a way to test mssql * fix linters * Fix godot --------- Co-authored-by: Georgy Savva <georgy.savva@gmail.com>
1 parent 80c2cc6 commit d60e58c

File tree

11 files changed

+201
-14
lines changed

11 files changed

+201
-14
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
env:
1717
GO: ${{ matrix.go-version }}
1818
runs-on: ubuntu-latest
19+
services:
20+
mssql:
21+
image: mcr.microsoft.com/mssql/server:2019-latest
22+
env:
23+
SA_PASSWORD: p@sSword
24+
ACCEPT_EULA: "Y"
25+
ports:
26+
- 1433:1433
1927
steps:
2028
- name: Download CockroachDB Binary
2129
run: |
@@ -45,7 +53,7 @@ jobs:
4553
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
4654

4755
- name: Test
48-
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... --cockroach-binary cockroach
56+
run: go test --tags with_mssql -v -race -coverprofile=coverage.txt -covermode=atomic ./... --cockroach-binary cockroach
4957

5058
- name: Upload Codecov
5159
uses: codecov/codecov-action@v3

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ linters-settings:
8282
- whyNoLint
8383
gocyclo:
8484
min-complexity: 15
85-
godot:
86-
check-all: true
8785
goimports:
8886
local-prefixes: github.com/georgysavva/scany
8987
gomnd:

dbscan/dbscan.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Rows interface {
1616
Next() bool
1717
Columns() ([]string, error)
1818
Scan(dest ...interface{}) error
19+
NextResultSet() bool
1920
}
2021

2122
// ScanAll is a package-level helper function that uses the DefaultAPI object.
@@ -30,6 +31,12 @@ func ScanOne(dst interface{}, rows Rows) error {
3031
return DefaultAPI.ScanOne(dst, rows)
3132
}
3233

34+
// ScanAllSets is a package-level helper function that uses the DefaultAPI object.
35+
// See API.ScanAllSets for details.
36+
func ScanAllSets(dsts []interface{}, rows Rows) error {
37+
return DefaultAPI.ScanAllSets(dsts, rows)
38+
}
39+
3340
// NameMapperFunc is a function type that maps a struct field name to the database column name.
3441
type NameMapperFunc func(string) string
3542

@@ -162,7 +169,7 @@ func WithAllowUnknownColumns(allowUnknownColumns bool) APIOption {
162169
// Before starting, ScanAll resets the destination slice,
163170
// so if it's not empty it will overwrite all existing elements.
164171
func (api *API) ScanAll(dst interface{}, rows Rows) error {
165-
return api.processRows(dst, rows, true /* multipleRows. */)
172+
return api.processRows(dst, rows, true /* multipleRows. */, true /* closeRows. */)
166173
}
167174

168175
// ScanOne iterates all rows to the end and makes sure that there was exactly one row
@@ -171,7 +178,22 @@ func (api *API) ScanAll(dst interface{}, rows Rows) error {
171178
// and propagates any errors that could pop up.
172179
// It scans data from that single row into the destination.
173180
func (api *API) ScanOne(dst interface{}, rows Rows) error {
174-
return api.processRows(dst, rows, false /* multipleRows. */)
181+
return api.processRows(dst, rows, false /* multipleRows. */, true /* closeRows. */)
182+
}
183+
184+
// ScanAllSets iterates all rows to the end and scans data into each destination.
185+
// Multiple destinations is supported by multiple result sets.
186+
func (api *API) ScanAllSets(dsts []interface{}, rows Rows) error {
187+
defer rows.Close() //nolint: errcheck
188+
for i, dst := range dsts {
189+
if err := api.processRows(dst, rows, true, false /* closeRows */); err != nil {
190+
return fmt.Errorf("error processing destination %d: %w", i, err)
191+
}
192+
if !rows.NextResultSet() {
193+
break
194+
}
195+
}
196+
return nil
175197
}
176198

177199
// NotFound returns true if err is a not found error.
@@ -189,8 +211,10 @@ type sliceDestinationMeta struct {
189211
elementByPtr bool
190212
}
191213

192-
func (api *API) processRows(dst interface{}, rows Rows, multipleRows bool) error {
193-
defer rows.Close() //nolint: errcheck
214+
func (api *API) processRows(dst interface{}, rows Rows, multipleRows, closeRows bool) error {
215+
if closeRows {
216+
defer rows.Close() //nolint: errcheck
217+
}
194218
var sliceMeta *sliceDestinationMeta
195219
if multipleRows {
196220
var err error
@@ -219,9 +243,10 @@ func (api *API) processRows(dst interface{}, rows Rows, multipleRows bool) error
219243
if err := rows.Err(); err != nil {
220244
return fmt.Errorf("scany: rows final error: %w", err)
221245
}
222-
223-
if err := rows.Close(); err != nil {
224-
return fmt.Errorf("scany: close rows after processing: %w", err)
246+
if closeRows {
247+
if err := rows.Close(); err != nil {
248+
return fmt.Errorf("scany: close rows after processing: %w", err)
249+
}
225250
}
226251

227252
exactlyOneRow := !multipleRows

dbscan/rowscanner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ func (er emptyRow) Next() bool { return true }
848848
func (er emptyRow) Columns() ([]string, error) { return []string{}, nil }
849849
func (er emptyRow) Close() error { return nil }
850850
func (er emptyRow) Err() error { return nil }
851+
func (er emptyRow) NextResultSet() bool { return false }
851852

852853
func TestRowScanner_Scan_primitiveTypeDestinationRowsContainZeroColumns_returnsErr(t *testing.T) {
853854
t.Parallel()

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3.2"
2+
services:
3+
sql-server-db:
4+
image: mcr.microsoft.com/mssql/server:2017-latest
5+
ports:
6+
- "1433:1433"
7+
environment:
8+
SA_PASSWORD: "p@sSword"
9+
ACCEPT_EULA: "Y"

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ go 1.18
55
require (
66
github.com/cockroachdb/cockroach-go/v2 v2.2.0
77
github.com/jackc/pgx/v5 v5.0.0
8-
github.com/stretchr/testify v1.8.0
8+
github.com/microsoft/go-mssqldb v1.6.0
9+
github.com/stretchr/testify v1.8.4
910
)
1011

1112
require (
1213
github.com/davecgh/go-spew v1.1.1 // indirect
1314
github.com/gofrs/flock v0.8.1 // indirect
15+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
16+
github.com/golang-sql/sqlexp v0.1.0 // indirect
1417
github.com/jackc/pgpassfile v1.0.0 // indirect
1518
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
1619
github.com/jackc/puddle/v2 v2.0.0 // indirect
1720
github.com/lib/pq v1.10.0 // indirect
1821
github.com/pkg/errors v0.9.1 // indirect
1922
github.com/pmezard/go-difflib v1.0.0 // indirect
2023
github.com/rogpeppe/go-internal v1.9.0 // indirect
21-
github.com/stretchr/objx v0.4.0 // indirect
24+
github.com/stretchr/objx v0.5.0 // indirect
2225
golang.org/x/crypto v0.17.0 // indirect
2326
golang.org/x/sys v0.15.0 // indirect
2427
golang.org/x/text v0.14.0 // indirect

go.sum

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 h1:/iHxaJhsFr0+xVFfbMr5vxz848jyiWuIEDhYq3y5odY=
2+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
3+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
4+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0 h1:yfJe15aSwEQ6Oo6J+gdfdulPNoZ3TEhmbhLIoxZcA+U=
5+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 h1:T028gtTPiYt/RMUfs8nVsAL7FDQrfLlrm/NnRG/zcC4=
6+
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpCKs6LGGLAhwBARt9632unrVcI6i8s/8os=
17
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
28
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
39
github.com/cockroachdb/cockroach-go/v2 v2.2.0 h1:/5znzg5n373N/3ESjHF5SMLxiW4RKB05Ql//KWfeTFs=
@@ -13,7 +19,13 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
1319
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
1420
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
1521
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
22+
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
23+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
24+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
25+
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
26+
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
1627
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
28+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
1729
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
1830
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
1931
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
@@ -73,6 +85,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
7385
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
7486
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
7587
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
88+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
7689
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
7790
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
7891
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -88,6 +101,9 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
88101
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
89102
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
90103
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
104+
github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc=
105+
github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU=
106+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
91107
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
92108
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
93109
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -108,15 +124,17 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
108124
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
109125
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
110126
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
111-
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
112127
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
128+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
129+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
113130
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
114131
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
115132
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
116133
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
117134
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
118-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
119135
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
136+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
137+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
120138
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
121139
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
122140
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@@ -143,6 +161,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
143161
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
144162
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
145163
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
164+
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
146165
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
147166
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
148167
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

pgxscan/pgxscan.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ func (ra RowsAdapter) Close() error {
180180
return nil
181181
}
182182

183+
// NextResultSet is currently always returning false.
184+
func (ra RowsAdapter) NextResultSet() bool {
185+
// TODO: when pgx issue #308 and #1512 and is fixed mabye we can do something here.
186+
return false
187+
}
188+
183189
func mustNewDBScanAPI(opts ...dbscan.APIOption) *dbscan.API {
184190
api, err := NewDBScanAPI(opts...)
185191
if err != nil {

sqlscan/sqlscan.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func ScanOne(dst interface{}, rows *sql.Rows) error {
4545
return DefaultAPI.ScanOne(dst, rows)
4646
}
4747

48+
// ScanAllSets is a package-level helper function that uses the DefaultAPI object.
49+
// See API.ScanAllSets for details.
50+
func ScanAllSets(dsts []interface{}, rows *sql.Rows) error {
51+
return DefaultAPI.ScanAllSets(dsts, rows)
52+
}
53+
4854
// RowScanner is a wrapper around the dbscan.RowScanner type.
4955
// See dbscan.RowScanner for details.
5056
type RowScanner struct {
@@ -133,6 +139,12 @@ func (api *API) ScanOne(dst interface{}, rows *sql.Rows) error {
133139
}
134140
}
135141

142+
// ScanAllSets is a wrapper around the dbscan.ScanAllSets function.
143+
// See dbscan.ScanAllSets for details.
144+
func (api *API) ScanAllSets(dsts []interface{}, rows *sql.Rows) error {
145+
return api.dbscanAPI.ScanAllSets(dsts, rows)
146+
}
147+
136148
// NotFound is a helper function to check if an error
137149
// is `sql.ErrNoRows`.
138150
func NotFound(err error) bool {

sqlscan/sqlscan_ms_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//go:build with_mssql
2+
// +build with_mssql
3+
4+
package sqlscan_test
5+
6+
import (
7+
"database/sql"
8+
"fmt"
9+
"os"
10+
"testing"
11+
12+
"github.com/georgysavva/scany/v2/sqlscan"
13+
_ "github.com/microsoft/go-mssqldb"
14+
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
16+
)
17+
18+
const (
19+
multipleSetsQueryMssql = `
20+
SELECT *
21+
FROM (
22+
VALUES ('foo val', 'bar val'), ('foo val 2', 'bar val 2'), ('foo val 3', 'bar val 3')
23+
) as t1 (foo, bar);
24+
25+
26+
SELECT *
27+
FROM (
28+
VALUES ('egg val', 'bacon val')
29+
) as t2 (egg, bacon);
30+
`
31+
)
32+
33+
func getEnv(key string, defaultValue string) string {
34+
value, exists := os.LookupEnv(key)
35+
if !exists {
36+
return defaultValue
37+
}
38+
return value
39+
}
40+
func TestMSScanAllSets(t *testing.T) {
41+
t.Parallel()
42+
testSqliteDB, err := sql.Open("sqlserver", getEnv("MSSQL_URL", "sqlserver://sa:p@sSword@localhost:1433?database=master"))
43+
if err != nil {
44+
require.NoError(t, err)
45+
}
46+
dbscanAPI, err := sqlscan.NewDBScanAPI()
47+
if err != nil {
48+
require.NoError(t, fmt.Errorf("new DB scan API: %w", err))
49+
}
50+
api, err := sqlscan.NewAPI(dbscanAPI)
51+
if err != nil {
52+
require.NoError(t, fmt.Errorf("new API: %w", err))
53+
}
54+
type testModel2 struct {
55+
Egg string
56+
Bacon string
57+
}
58+
59+
expected1 := []*testModel{
60+
{Foo: "foo val", Bar: "bar val"},
61+
{Foo: "foo val 2", Bar: "bar val 2"},
62+
{Foo: "foo val 3", Bar: "bar val 3"},
63+
}
64+
expected2 := []*testModel2{
65+
{Egg: "egg val", Bacon: "bacon val"},
66+
}
67+
68+
rows, err := testSqliteDB.Query(multipleSetsQueryMssql)
69+
require.NoError(t, err)
70+
71+
var got1 []*testModel
72+
var got2 []*testModel2
73+
err = api.ScanAllSets([]any{&got1, &got2}, rows)
74+
require.NoError(t, err)
75+
76+
assert.Equal(t, expected1, got1)
77+
assert.Equal(t, expected2, got2)
78+
}

0 commit comments

Comments
 (0)