-
Notifications
You must be signed in to change notification settings - Fork 0
/
aqlquerier.go
76 lines (62 loc) · 1.9 KB
/
aqlquerier.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
package aqlquerier
import (
"context"
"database/sql"
"database/sql/driver"
"github.com/bsn-si/IPEHR-gateway/src/pkg/aqlprocessor"
"github.com/bsn-si/IPEHR-gateway/src/pkg/errors"
"github.com/bsn-si/IPEHR-gateway/src/pkg/storage/treeindex"
)
func init() {
sql.Register("aql", &AQLDriver{})
}
type AQLDriver struct{}
func (svc *AQLDriver) Open(name string) (driver.Conn, error) {
conn := &AQLConn{
index: treeindex.DefaultEHRIndex,
}
return conn, nil
}
type AQLConn struct {
index *treeindex.EHRIndex
}
// Prepare returns a prepared statement, bound to this connection.
func (conn *AQLConn) Prepare(query string) (driver.Stmt, error) {
return conn.PrepareContext(context.Background(), query)
}
func (conn *AQLConn) PrepareContext(_ context.Context, query string) (driver.Stmt, error) {
aqlQuery, err := aqlprocessor.NewAqlProcessor(query).Process()
if err != nil {
return nil, errors.Wrap(err, "cannot prepare AQL query")
}
stmt := &Stmt{
query: aqlQuery,
index: conn.index,
}
return stmt, nil
}
// implements driver.Tx interface
// Rollback - not implemented ...
func (conn *AQLConn) Rollback() error {
return errors.New("Rollback method not implemented")
}
// Close invalidates and potentially stops any current
// prepared statements and transactions, marking this
// connection as no longer in use.
//
// Because the sql package maintains a free pool of
// connections and only calls Close when there's a surplus of
// idle connections, it shouldn't be necessary for drivers to
// do their own connection caching.
//
// Drivers must ensure all network calls made by Close
// do not block indefinitely (e.g. apply a timeout).
func (conn *AQLConn) Close() error {
return nil
}
// Begin starts and returns a new transaction.
//
// Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
func (conn *AQLConn) Begin() (driver.Tx, error) {
return nil, errors.New("not implemented")
}