sqler

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const TagName = "sqler"

Variables

This section is empty.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

func Mapping

func Mapping(data interface{}) map[string]interface{}

Mapping 将结构体转换成 map

func Scan

func Scan(rs *sql.Rows, target interface{}) error

func ScanToMap

func ScanToMap(rs *sql.Rows) ([]map[string]interface{}, error)

ScanToMap 将 SQL 查询结构 序列化到一个 map 中

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(ops Options) (*DB, error)

NewDB -

func (*DB) Begin added in v0.1.4

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

Begin 开启一个事务

func (*DB) BeginCtx added in v0.1.4

func (db *DB) BeginCtx(ctx context.Context, opts *TxOptions) (*Tx, error)

BeginCtx 开启一个事务

func (*DB) Close

func (db *DB) Close() error

Close 关闭数据库连接

func (*DB) Count

func (db *DB) Count(name string, where Where, col string) (int64, error)

Count 获取数据条数

func (*DB) Delete

func (db *DB) Delete(name string, where Where) (int64, error)

Delete 删除数据

func (*DB) Insert

func (db *DB) Insert(name string, data map[string]interface{}) (int64, error)

Insert 单行插入

func (*DB) Modify

func (db *DB) Modify(name string, where Where, update map[string]interface{}) (int64, error)

Modify 变更数据

func (*DB) MultiInsert

func (db *DB) MultiInsert(name string, data []map[string]interface{}) (int64, error)

MultiInsert 多行插入

func (*DB) Select

func (db *DB) Select(name string, where Where, fields Fields) *Fruit

Select 查询数据

type Fields

type Fields []string

type Fruit

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

func (*Fruit) Close

func (rs *Fruit) Close()

func (*Fruit) ConvertTo

func (rs *Fruit) ConvertTo(target interface{}) error

func (*Fruit) ConvertToMap

func (rs *Fruit) ConvertToMap() ([]map[string]interface{}, error)

func (*Fruit) Error

func (rs *Fruit) Error() error

func (*Fruit) Rows

func (rs *Fruit) Rows() *sql.Rows

type Options

type Options struct {
	Driver  string `yaml:"driver" mapstructure:"driver"`
	ConnStr string `yaml:"dsn" mapstructure:"dsn"`
	// 定时保活
	KeepAlive int `yaml:"keep_alive" mapstructure:"keep_alive"`
	// 最大可空闲连接数量
	MaxIdles int `yaml:"max_idles" mapstructure:"max_idles"`
	// 最大连接数量
	MaxOpens    int `yaml:"max_opens" mapstructure:"max_opens"`
	MaxLifeTime int `yaml:"max_life_time" mapstructure:"max_life_time"`
}

type Tx added in v0.1.4

type Tx struct {
	*sql.Tx
}

Tx 事务

func (*Tx) Commit added in v0.1.4

func (tx *Tx) Commit() error

Commit 事务提交

func (*Tx) Delete added in v0.1.4

func (tx *Tx) Delete(name string, where Where) (int64, error)

Delete 删除数据

func (*Tx) Insert added in v0.1.4

func (tx *Tx) Insert(name string, data map[string]interface{}) (int64, error)

Insert 插入单行数据

func (*Tx) Modify added in v0.1.4

func (tx *Tx) Modify(name string, where Where, update map[string]interface{}) (int64, error)

Modify 修改数据

func (*Tx) MultiInsert added in v0.1.4

func (tx *Tx) MultiInsert(name string, data []map[string]interface{}) (int64, error)

MultiInsert 插入多行

func (*Tx) Rollback added in v0.1.4

func (tx *Tx) Rollback() error

Rollback 回滚事务

func (*Tx) RollbackSavePoint added in v0.1.4

func (tx *Tx) RollbackSavePoint(tag string) error

RollbackSavePoint 回滚到指定 SavePoint

func (*Tx) Select added in v0.1.4

func (tx *Tx) Select(name string, where Where, fields Fields) *Fruit

Select execute select by transaction

func (*Tx) SetSavePoint added in v0.1.4

func (tx *Tx) SetSavePoint() (string, error)

SetSavePoint Create SavePoint

type TxOptions added in v0.1.4

type TxOptions = sql.TxOptions

TxOptions 事务配置项,类型别名

type Where

type Where map[string]interface{}

Jump to

Keyboard shortcuts

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