forked from microsoft/gocosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.go
53 lines (44 loc) · 1.38 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
52
53
package gocosmos
import (
"context"
"database/sql/driver"
"errors"
"time"
)
var (
locGmt, _ = time.LoadLocation("GMT")
)
// Conn is Azure Cosmos DB implementation of driver.Conn.
type Conn struct {
restClient *RestClient // Azure Cosmos DB REST API client.
defaultDb string // default database used in Cosmos DB operations.
}
// Prepare implements driver.Conn/Prepare.
func (c *Conn) Prepare(query string) (driver.Stmt, error) {
return c.PrepareContext(context.Background(), query)
}
// PrepareContext implements driver.ConnPrepareContext/PrepareContext.
//
// @Available since v0.2.1
func (c *Conn) PrepareContext(_ context.Context, query string) (driver.Stmt, error) {
return ParseQueryWithDefaultDb(c, c.defaultDb, query)
}
// Close implements driver.Conn/Close.
func (c *Conn) Close() error {
return nil
}
// Begin implements driver.Conn/Begin.
func (c *Conn) Begin() (driver.Tx, error) {
return c.BeginTx(context.Background(), driver.TxOptions{})
}
// BeginTx implements driver.ConnBeginTx/BeginTx.
//
// @Available since v0.2.1
func (c *Conn) BeginTx(_ context.Context, _ driver.TxOptions) (driver.Tx, error) {
return nil, errors.New("transaction is not supported")
}
// CheckNamedValue implements driver.NamedValueChecker/CheckNamedValue.
func (c *Conn) CheckNamedValue(_ *driver.NamedValue) error {
// since Cosmos DB is document db, it accepts any value types
return nil
}