forked from dolthub/go-mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
66 lines (50 loc) · 1.17 KB
/
helpers_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package driver_test
import (
"database/sql"
"reflect"
"sync"
"testing"
"github.com/stretchr/testify/require"
"github.com/dolthub/go-mysql-server/driver"
)
type V = interface{}
var driverMu sync.Mutex
var drivers = map[driver.Provider]*driver.Driver{}
func sqlOpen(t *testing.T, provider driver.Provider, dsn string) *sql.DB {
driverMu.Lock()
drv, ok := drivers[provider]
if !ok {
drv = driver.New(provider, driver.Options{})
drivers[provider] = drv
}
driverMu.Unlock()
conn, err := drv.OpenConnector(dsn)
require.NoError(t, err)
return sql.OpenDB(conn)
}
type Pointers []V
func (ptrs Pointers) Values() []V {
values := make([]V, len(ptrs))
for i := range values {
values[i] = reflect.ValueOf(ptrs[i]).Elem().Interface()
}
return values
}
type Records [][]V
func (records Records) Rows(rows ...int) Records {
result := make(Records, len(rows))
for i := range rows {
result[i] = records[rows[i]]
}
return result
}
func (records Records) Columns(cols ...int) Records {
result := make(Records, len(records))
for i := range records {
result[i] = make([]V, len(cols))
for j := range cols {
result[i][j] = records[i][cols[j]]
}
}
return result
}