This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_service.go
67 lines (60 loc) · 2.22 KB
/
data_service.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
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apid
import (
"context"
"database/sql"
"time"
)
type DataService interface {
DB() (DB, error)
DBForID(id string) (db DB, err error)
DBVersion(version string) (db DB, err error)
DBVersionForID(id, version string) (db DB, err error)
// will set DB to close and delete when no more references
ReleaseDB(version string)
ReleaseCommonDB()
ReleaseDBForID(id, version string)
}
type DB interface {
Ping() error
Prepare(query string) (*sql.Stmt, error)
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
Begin() (Tx, error)
Stats() sql.DBStats
SetConnMaxLifetime(d time.Duration)
SetMaxIdleConns(n int)
SetMaxOpenConns(n int)
QueryStructs(dest interface{}, query string, args ...interface{}) error
//Close() error
//Stats() sql.DBStats
//Driver() driver.Driver
}
type Tx interface {
Commit() error
Exec(query string, args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Prepare(query string) (*sql.Stmt, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
Rollback() error
Stmt(stmt *sql.Stmt) *sql.Stmt
StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
QueryStructs(dest interface{}, query string, args ...interface{}) error
}