-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrows.go
More file actions
51 lines (41 loc) · 1003 Bytes
/
rows.go
File metadata and controls
51 lines (41 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sqlmock
import (
"database/sql/driver"
"io"
)
// Rows implements driver.Rows with in-memory row data.
type Rows struct {
columns []string
data [][]driver.Value
index int
}
// NewRows creates a row container with the provided column names.
func NewRows(columns []string) *Rows {
return &Rows{columns: columns}
}
// AddRows appends one row of values and returns the same Rows for chaining.
func (r *Rows) AddRows(values ...any) *Rows {
row := make([]driver.Value, len(values))
for i, v := range values {
row[i] = v
}
r.data = append(r.data, row)
return r
}
// Columns returns the configured column names.
func (r *Rows) Columns() []string {
return r.columns
}
// Next copies the next row into dest or returns io.EOF when no rows remain.
func (r *Rows) Next(dest []driver.Value) error {
if r.index >= len(r.data) {
return io.EOF
}
copy(dest, r.data[r.index])
r.index++
return nil
}
// Close closes the rows iterator.
func (r *Rows) Close() error {
return nil
}