sqldb

package
v0.0.0-...-d22e7c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, driver, dsn string, connOpts *ConnectOptions) (*sqlx.DB, error)

Connect to a new database

Types

type ConnectOptions

type ConnectOptions struct {
	Retry                 int
	MaxOpenConnections    int
	MaxIdleConnections    int
	ConnectionMaxLifetime time.Duration
}

ConnectOptions to list options when connect to the db

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB struct to hold all database connections

func Wrap

func Wrap(ctx context.Context, leader, follower *sqlx.DB) (*DB, error)

Wrap leader and follower sqlx object to one DB object this is for easier usage, so user doesn't have to specify leader or follower all exec is going to leader, all query is going to follower

func (*DB) Begin

func (db *DB) Begin() (*sql.Tx, error)

Begin return sql transaction object, begin a transaction

func (*DB) Beginx

func (db *DB) Beginx() (*sqlx.Tx, error)

Beginx return sqlx transaction object, begin a transaction

func (*DB) BindNamed

func (db *DB) BindNamed(query string, arg interface{}) (string, interface{}, error)

BindNamed return named query wrapped with bind

func (*DB) Close

func (db *DB) Close() error

Close all database connection to leader and replica

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec function

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext function

func (*DB) Follower

func (db *DB) Follower() *sqlx.DB

Follower return follower database connection

func (*DB) Get

func (db *DB) Get(dest interface{}, query string, args ...interface{}) error

Get return one value in destination using relfection

func (*DB) GetContext

func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext function

func (*DB) Leader

func (db *DB) Leader() *sqlx.DB

Leader return leader database connection

func (*DB) Named

func (db *DB) Named(query string, arg interface{}) (string, interface{}, error)

Named return named query and parameters

func (*DB) NamedExec

func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error)

NamedExec execute query with named parameter

func (*DB) NamedExecContext

func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

NamedExecContext function

func (*DB) NamedQuery

func (db *DB) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)

NamedQuery function

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query function

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext function

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow function

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext function

func (*DB) Rebind

func (db *DB) Rebind(query string) string

Rebind query

func (*DB) Select

func (db *DB) Select(dest interface{}, query string, args ...interface{}) error

Select return more than one value in destintion using reflection

func (*DB) SelectContext

func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext fuction

func (*DB) SetConnMaxLifetime

func (db *DB) SetConnMaxLifetime(t time.Duration)

SetConnMaxLifetime to sql database

func (*DB) SetMaxIdleConns

func (db *DB) SetMaxIdleConns(n int)

SetMaxIdleConns to sql database

func (*DB) SetMaxOpenConns

func (db *DB) SetMaxOpenConns(n int)

SetMaxOpenConns to sql database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL