-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrows.go
51 lines (46 loc) · 1.07 KB
/
rows.go
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 mydb
import (
"database/sql/driver"
"io"
)
// MyRowS myRowS implemmet for driver.Rows
type MyRowS struct {
Size int64
}
// Columns returns the names of the columns. The number of
// columns of the result is inferred from the length of the
// slice. If a particular column name isn't known, an empty
// string should be returned for that entry.
func (r *MyRowS) Columns() []string {
return []string{
"name",
"age",
"version",
}
}
// Close closes the rows iterator.
func (r *MyRowS) Close() error {
return nil
}
// Next is called to populate the next row of data into
// the provided slice. The provided slice will be the same
// size as the Columns() are wide.
//
// Next should return io.EOF when there are no more rows.
//
// The dest should not be written to outside of Next. Care
// should be taken when closing Rows not to modify
// a buffer held in dest.
func (r *MyRowS) Next(dest []driver.Value) error {
if r.Size == 0 {
return io.EOF
}
name := "dalong"
age := 333
version := "v1"
dest[0] = name
dest[1] = age
dest[2] = version
r.Size--
return nil
}