db

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MysqlParent = MysqlMode("parent")
	MysqlChild  = MysqlMode("child")
)

Variables

View Source
var (
	ErrNoTx = errors.New("no tx")
)

Functions

func Add

func Add(table string, insertData map[string]interface{}) (int64, error)

func Delete

func Delete(table string, condition map[string]interface{}) (int64, error)

* Delete

func Exec

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

func Query

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

func QueryRow

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

func Update

func Update(table string, updateData map[string]interface{}, condition map[string]interface{}) (int64, error)

* Update

Types

type Mysql

type Mysql struct {
	Instance *sql.DB
}

func NewMysql

func NewMysql(config MysqlConfig) *Mysql

func Setup

func Setup(configs []MysqlConfig) *Mysql

func (Mysql) Close

func (db Mysql) Close()

func (Mysql) Open

func (db Mysql) Open()

type MysqlConfig

type MysqlConfig struct {
	Host     string    `yaml:"Host"`
	Port     int       `yaml:"Port"`
	User     string    `yaml:"User"`
	Password string    `yaml:"Password"`
	Database string    `yaml:"Database"`
	Mode     MysqlMode `yaml:"Mode"`
}

type MysqlMode

type MysqlMode string

type TxInstance

type TxInstance struct {
	Tx *sql.Tx
}

func BeginTx

func BeginTx() (*TxInstance, error)

func (*TxInstance) Add

func (i *TxInstance) Add(table string, insertData map[string]interface{}) (int64, error)

func (*TxInstance) Commit

func (i *TxInstance) Commit() error

func (*TxInstance) Delete

func (i *TxInstance) Delete(table string, condition map[string]interface{}) (int64, error)

func (*TxInstance) Rollback

func (i *TxInstance) Rollback() error

func (*TxInstance) Update

func (i *TxInstance) Update(table string, updateData map[string]interface{}, condition map[string]interface{}) (int64, error)

Jump to

Keyboard shortcuts

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