-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.go
51 lines (43 loc) · 1.25 KB
/
conn.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 tablestore
import (
"database/sql/driver"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
)
type conn struct {
client *tablestore.TableStoreClient
}
func newConn(cfg *connectionConfig) *conn {
return &conn{
client: tablestore.NewClientWithConfig(cfg.endPoint, cfg.instanceName, cfg.accessKeyId, cfg.accessKeySecret, "", cfg.otsConfig),
}
}
// Prepare returns a prepared statement, bound to this connection.
func (c *conn) Prepare(query string) (driver.Stmt, error) {
return newStmt(c.client, query), nil
}
// Close invalidates and potentially stops any current
// prepared statements and transactions, marking this
// connection as no longer in use.
func (c *conn) Close() error {
return nil
}
// Begin starts and returns a new transaction.
func (c *conn) Begin() (driver.Tx, error) {
return nil, ErrNotSupported
}
// Exec implements the driver.Execer
func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
stmt, err := c.Prepare(query)
if err != nil {
return nil, err
}
return stmt.Exec(args)
}
// Query implements the driver.Queryer
func (c *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
stmt, err := c.Prepare(query)
if err != nil {
return nil, err
}
return stmt.Query(args)
}