dbx

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMySQLDSN = "%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=true"

Variables

This section is empty.

Functions

func NewTransaction

func NewTransaction(ctx context.Context, db Database, fn func(ctx context.Context, tx Transaction) error) (err error)

Types

type DSN

type DSN struct {
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
}

type Database

type Database interface {
	Begin() (Transaction, error)
	Ping() error
}

func ConnectMySQL

func ConnectMySQL(format string, data DSN) (db Database, err error)

type DatabaseSQLX

type DatabaseSQLX struct {
	*sqlx.DB
}

func (*DatabaseSQLX) Begin

func (db *DatabaseSQLX) Begin() (Transaction, error)

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error

	Get(dst interface{}, query string, args ...interface{}) error
	Select(dst interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	GetContext(ctx context.Context, dst interface{}, query string, args ...interface{}) error
	SelectContext(ctx context.Context, dst interface{}, query string, args ...interface{}) error
}

type Tx

type Tx struct {
	*sqlx.Tx
}

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) Rollback

func (t *Tx) Rollback() error

Jump to

Keyboard shortcuts

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