Documentation
¶
Index ¶
- type CPool
- type DB
- func (db *DB) Begin() (*sql.Tx, error)
- func (db *DB) Close() error
- func (db *DB) Driver() driver.Driver
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) New() *DB
- func (db *DB) Ping() error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Prepare(query string) (Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (Stmt, error)
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRow(query string, args ...interface{}) Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- func (db *DB) SetSticky(stick bool)
- type Row
- type Stmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CPool ¶
type CPool struct {
// contains filtered or unexported fields
}
CPool holds the master and slave connection pools
func (*CPool) AddWriter ¶
AddWriter prepend a db connection to the pool Previous writer automatically become a reader
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB holds connection pool(s) This should be created once, and for each acquaring of new db pool, use New()
func (*DB) Begin ¶
Begin starts a transaction on Writer It's likely the subsequent queries will perform a write
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext execute a query with context and mark the db as modified
func (*DB) PingContext ¶
PingContext pings all physical dbs with context
func (*DB) PrepareContext ¶
PrepareContext two statements, one in Writer one in Reader The statement will be executed in the writer and queries in reader
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. The query will be performed in the next connection
func (*DB) QueryRowContext ¶
QueryRowContext perform the underline QueryRowContext of sql.DB on the next connection
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused for all connections. This is concurrency safe.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the max idel conns for all connections. This is concurrency safe.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the max open connections limit for all connections. This is concurrency safe.
type Row ¶
type Row interface {
Scan(dest ...interface{}) error
}
Row allow us to write our custom row struct
type Stmt ¶
type Stmt interface { Close() error Exec(args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error) Query(args ...interface{}) (*sql.Rows, error) QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error) QueryRow(args ...interface{}) Row QueryRowContext(ctx context.Context, args ...interface{}) Row }
Stmt allows DB