-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibrary_connection_pool_adapter.go
40 lines (33 loc) · 1.15 KB
/
library_connection_pool_adapter.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
package sqldb
import (
"context"
"database/sql"
)
type LibraryConnectionPoolAdapter struct {
*sql.DB
txOptions *sql.TxOptions
}
func NewLibraryConnectionPoolAdapter(actual *sql.DB, txOptions *sql.TxOptions) *LibraryConnectionPoolAdapter {
return &LibraryConnectionPoolAdapter{DB: actual, txOptions: txOptions}
}
func (this *LibraryConnectionPoolAdapter) Ping(ctx context.Context) error {
return this.DB.PingContext(ctx)
}
func (this *LibraryConnectionPoolAdapter) BeginTransaction(ctx context.Context) (Transaction, error) {
if tx, err := this.DB.BeginTx(ctx, this.txOptions); err == nil {
return NewLibraryTransactionAdapter(tx), nil
} else {
return nil, err
}
}
func (this *LibraryConnectionPoolAdapter) Execute(ctx context.Context, query string, parameters ...interface{}) (uint64, error) {
if result, err := this.DB.ExecContext(ctx, query, parameters...); err != nil {
return 0, err
} else {
count, _ := result.RowsAffected()
return uint64(count), nil
}
}
func (this *LibraryConnectionPoolAdapter) Select(ctx context.Context, query string, parameters ...interface{}) (SelectResult, error) {
return this.DB.QueryContext(ctx, query, parameters...)
}