-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
110 lines (96 loc) · 2.52 KB
/
connection.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package aerospike
import (
"context"
"database/sql/driver"
"fmt"
as "github.com/aerospike/aerospike-client-go/v6"
"github.com/viant/sqlparser"
)
type connection struct {
cfg *Config
client *as.Client
sets *registry
writeLimiter *limiter
}
// Prepare returns a prepared statement, bound to this connection.
func (c *connection) Prepare(query string) (driver.Stmt, error) {
return c.PrepareContext(context.Background(), query)
}
// PrepareContext returns a prepared statement, bound to this connection.
func (c *connection) PrepareContext(ctx context.Context, SQL string) (driver.Stmt, error) {
kind := sqlparser.ParseKind(SQL)
c.sets.Merge(globalSets)
stmt := &Statement{
SQL: SQL,
kind: kind,
sets: c.sets,
client: c.client,
cfg: c.cfg,
namespace: c.cfg.namespace,
writeLimiter: c.writeLimiter,
}
stmt.checkQueryParameters()
switch kind {
case sqlparser.KindSelect:
if err := stmt.prepareSelect(SQL); err != nil {
return nil, err
}
case sqlparser.KindInsert:
if err := stmt.prepareInsert(SQL); err != nil {
return nil, err
}
case sqlparser.KindUpdate:
if err := stmt.prepareUpdate(SQL); err != nil {
return nil, err
}
case sqlparser.KindDelete:
if err := stmt.prepareDelete(SQL); err != nil {
return nil, err
}
case sqlparser.KindTruncateTable:
if err := stmt.parseTruncateTable(SQL); err != nil {
return nil, err
}
case sqlparser.KindRegisterSet:
case sqlparser.KindCreateIndex:
if err := stmt.prepareCreateIndex(SQL); err != nil {
return nil, err
}
return stmt, nil
case sqlparser.KindDropIndex:
if err := stmt.prepareDropIndex(SQL); err != nil {
return nil, err
}
return stmt, nil
default:
return nil, fmt.Errorf("unsupported kind: %v for DDL: %v", kind, SQL)
}
if err := stmt.setTypeBasedMapper(); err != nil {
return nil, err
}
return stmt, nil
}
// Ping pings server
func (c *connection) Ping(ctx context.Context) error {
return nil
}
// Begin starts and returns a new transaction.
func (c *connection) Begin() (driver.Tx, error) {
return &tx{c}, nil
}
// BeginTx starts and returns a new transaction.
func (c *connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
return &tx{c}, nil
}
// Close closes connection
func (c *connection) Close() error {
return nil
}
// ResetSession resets session
func (c *connection) ResetSession(ctx context.Context) error {
return nil
}
// IsValid check is connection is valid
func (c *connection) IsValid() bool {
return true
}