-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconnection.go
More file actions
69 lines (59 loc) · 1.65 KB
/
connection.go
File metadata and controls
69 lines (59 loc) · 1.65 KB
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
package sql
import (
"context"
"database/sql/driver"
"fmt"
"github.com/viant/afs"
sqlparser "github.com/viant/sqlparser"
"github.com/viant/x"
)
// Connection represent connection
type Connection struct {
cfg *Config
types *x.Registry
fs afs.Service
}
// Prepare returns a prepared statement, bound to this Connection.
func (c *Connection) Prepare(SQL string) (driver.Stmt, error) {
return c.PrepareContext(context.Background(), SQL)
}
// 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)
if !(kind.IsRegisterType() || kind.IsSelect()) {
return nil, fmt.Errorf("unsupported SQL kind: %v", SQL)
}
c.types.Merge(globalTypes)
stmt := &Statement{SQL: SQL, Kind: kind, types: c.types, BaseURL: c.cfg.BaseURL, fs: c.fs}
stmt.checkQueryParameters()
if kind.IsSelect() {
if err := stmt.prepareSelect(SQL); 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 nil, nil
}
// BeginTx starts and returns a new transaction.
func (c *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
return nil, 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
}