db

package
v0.0.0-...-299d4c7 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DriverPostgres postgres
	DriverPostgres = `postgres`
	// DriverMySQL MySQL
	DriverMySQL = `mysql`
)

Variables

This section is empty.

Functions

func Exec

func Exec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error)

Exec execute

func Get

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

Get get one

func Limit

func Limit(page, pagesize int) string

Limit MySQL/PostgreSQL limit

func NamedExec

func NamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

NamedExec exec, named bindvars

func NamedGet

func NamedGet(dest interface{}, query string, args interface{}) (err error)

Get get one, named bindvars

func NamedSelect

func NamedSelect(dest interface{}, query string, args interface{}) (err error)

NamedSelect select rows, named bindvars

func Ping

func Ping() error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

func PingContext

func PingContext(ctx context.Context) error

PingContext verifies a connection to the database is still alive, establishing a connection if necessary.

func Release

func Release(dbx *DB) (err error)

Release release connect

func ReleaseDefault

func ReleaseDefault() error

ReleaseDefault release default connect

func Select

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

Select select rows

func SetDefaultOption

func SetDefaultOption(opt Option) (err error)

SetDefaultOption default connect option

func Stats

func Stats() sql.DBStats

Stats returns database statistics.

Types

type DB

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

DB db

func New

func New(opt Option) (dbx *DB, err error)

New new DB dynamic object

func (*DB) BeginTrans

func (d *DB) BeginTrans() (err error)

BeginTrans begin trans

func (*DB) Commit

func (d *DB) Commit() error

Commit commit

func (*DB) Connect

func (d *DB) Connect() (err error)

Connect connect to database

func (*DB) Exec

func (d *DB) Exec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error)

Exec exec

func (*DB) Get

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

Get get one

func (*DB) Limit

func (d *DB) Limit(page, pagesize int) string

Limit MySQL/PostgreSQL limit

func (*DB) NamedExec

func (d *DB) NamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

NamedExec exec, named bindvars

func (*DB) NamedGet

func (d *DB) NamedGet(dest interface{}, query string, args interface{}) (err error)

Get get one, named bindvars

func (*DB) NamedSelect

func (d *DB) NamedSelect(dest interface{}, query string, args interface{}) (err error)

NamedSelect select rows, named bindvars

func (*DB) Ping

func (d *DB) Ping() error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

func (*DB) PingContext

func (d *DB) PingContext(ctx context.Context) error

PingContext verifies a connection to the database is still alive, establishing a connection if necessary.

func (*DB) Rollback

func (d *DB) Rollback() error

Rollback rollback

func (*DB) Select

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

Select select rows

func (*DB) Stats

func (d *DB) Stats() sql.DBStats

Stats returns database statistics.

func (*DB) Trans

func (d *DB) Trans() (tx *Tx, err error)

Trans begin trans

func (*DB) TransExec

func (d *DB) TransExec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error)

TransNamedExec trans execute

func (*DB) TransGet

func (d *DB) TransGet(dest interface{}, query string, args ...interface{}) (err error)

TransGet trans get row

func (*DB) TransNamedExec

func (d *DB) TransNamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

TransNamedExec trans execute, named bindvars

func (*DB) TransNamedGet

func (d *DB) TransNamedGet(dest interface{}, query string, args interface{}) (err error)

TransNamedGet trans get row, named bindvars

func (*DB) TransSelect

func (d *DB) TransSelect(dest interface{}, query string, args ...interface{}) (err error)

TransSelect trans get rows

type Option

type Option struct {
	Driver       string
	DNS          string
	MaxOpenConns int
	MaxIdle      int
	MaxLifetime  time.Duration
}

Option option

type Tx

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

func BeginTrans

func BeginTrans() (tx *Tx, err error)

BeginTrans begin trans

func (*Tx) Commit

func (t *Tx) Commit() error

Commit commit

func (*Tx) Rollback

func (t *Tx) Rollback() error

Rollback rollback

func (*Tx) TransExec

func (t *Tx) TransExec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error)

TransNamedExec trans execute

func (*Tx) TransGet

func (t *Tx) TransGet(dest interface{}, query string, args ...interface{}) (err error)

TransGet trans get row

func (*Tx) TransNamedExec

func (t *Tx) TransNamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error)

TransNamedExec trans execute, named bindvars

func (*Tx) TransNamedGet

func (t *Tx) TransNamedGet(dest interface{}, query string, args interface{}) (err error)

TransNamedGet trans get row, named bindvars

func (*Tx) TransSelect

func (t *Tx) TransSelect(dest interface{}, query string, args ...interface{}) (err error)

TransSelect trans get rows

Jump to

Keyboard shortcuts

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