@@ -12,12 +12,14 @@ import (
12
12
// DB interface is a contract that supported by this library.
13
13
// All offered function of this library defined here.
14
14
// This supposed to be aligned with sql.DB, but since some of the functions is not relevant
15
- // with multi dbs connection, we decided to not support it
15
+ // with multi dbs connection, we decided to forward all single connection DB related function to the first primary DB
16
+ // For example, function like, `Conn()“, or `Stats()` only available for the primary DB, or the first primary DB (if using multi-primary)
16
17
type DB interface {
17
18
Begin () (* sql.Tx , error )
18
19
BeginTx (ctx context.Context , opts * sql.TxOptions ) (* sql.Tx , error )
19
20
Close () error
20
- Conn (ctx context.Context ) (* sql.Conn , error ) // db stats for only one of the primary db
21
+ // Conn only available for the primary db or the first primary db (if using multi-primary)
22
+ Conn (ctx context.Context ) (* sql.Conn , error )
21
23
Driver () driver.Driver
22
24
Exec (query string , args ... interface {}) (sql.Result , error )
23
25
ExecContext (ctx context.Context , query string , args ... interface {}) (sql.Result , error )
@@ -35,14 +37,15 @@ type DB interface {
35
37
SetMaxOpenConns (n int )
36
38
PrimaryDBs () []* sql.DB
37
39
ReplicaDBs () []* sql.DB
38
- Stats () sql.DBStats // db stats for only one of the primary db
40
+ // Stats only available for the primary db or the first primary db (if using multi-primary)
41
+ Stats () sql.DBStats
39
42
}
40
43
41
- // Supported LoadBalancer
42
- type (
43
- DBLoadBalancer LoadBalancer [ * sql. DB ]
44
- StmtLoadBalancer LoadBalancer [ * sql. Stmt ]
45
- )
44
+ // DBLoadBalancer is loadbalancer for physical DBs
45
+ type DBLoadBalancer LoadBalancer [ * sql. DB ]
46
+
47
+ // StmtLoadBalancer is loadbalancer for query prepared statements
48
+ type StmtLoadBalancer LoadBalancer [ * sql. Stmt ]
46
49
47
50
// sqlDB is a logical database with multiple underlying physical databases
48
51
// forming a single ReadWrite (primary) with multiple ReadOnly(replicas) db.
0 commit comments