mysql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MIT Imports: 10 Imported by: 88

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB 数据库管理

func NewDB

func NewDB(opts ...Option) (*DB, error)

NewDB 创建MySQL数据库实例

func (*DB) Close

func (d *DB) Close() error

Close 关闭数据库连接

func (*DB) CreateTableIfNotExists

func (d *DB) CreateTableIfNotExists(i interface{}, name string)

CreateTableIfNotExists 创建表

func (*DB) CreateTableIndex

func (d *DB) CreateTableIndex(table, idx string, unique bool, columns ...string)

CreateTableIndex 创建索引

func (*DB) DeleteByPK

func (d *DB) DeleteByPK(table string, pk M) (int64, error)

DeleteByPK 删除数据

func (*DB) DeleteByPKWithTran

func (d *DB) DeleteByPKWithTran(tran *gorp.Transaction, table string, pk M) (int64, error)

DeleteByPKWithTran 基于事物删除表数据

func (*DB) DeleteSQL

func (d *DB) DeleteSQL(table string, pk M) (string, []interface{})

DeleteSQL 获取删除SQL

func (*DB) In

func (d *DB) In(query string, args ...interface{}) (string, []interface{}, error)

In 组织带有IN查询的SQL和参数

func (*DB) InsertM

func (d *DB) InsertM(table string, info M) (int64, error)

InsertM 插入数据

func (*DB) InsertMWithTran

func (d *DB) InsertMWithTran(tran *gorp.Transaction, table string, info M) (int64, error)

InsertMWithTran 基于事物插入数据

func (*DB) InsertSQL

func (d *DB) InsertSQL(table string, info M) (string, []interface{})

InsertSQL 获取插入SQL

func (*DB) UpdateByPK

func (d *DB) UpdateByPK(table string, pk, info M) (int64, error)

UpdateByPK 更新数据

func (*DB) UpdateByPKWithTran

func (d *DB) UpdateByPKWithTran(tran *gorp.Transaction, table string, pk, info M) (int64, error)

UpdateByPKWithTran 基于事物更新数据

func (*DB) UpdateSQL

func (d *DB) UpdateSQL(table string, pk, info M) (string, []interface{})

UpdateSQL 获取更新SQL

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}

Logger 定义日志输出

type M

type M map[string]interface{}

M 定义字典类型

type Option

type Option func(*options)

Option 配置项

func SetDSN

func SetDSN(dsn string) Option

SetDSN 设置连接串

func SetEncoding

func SetEncoding(encoding string) Option

SetEncoding 设定数据库表的编码格式

func SetEngine

func SetEngine(engine string) Option

SetEngine 设定数据库表的存储引擎

func SetLogger

func SetLogger(logger Logger) Option

SetLogger 设定追踪日志

func SetMaxIdleConns

func SetMaxIdleConns(maxIdleConns int) Option

SetMaxIdleConns 设置空闲连接池中的最大连接数

func SetMaxLifetime

func SetMaxLifetime(maxLifetime time.Duration) Option

SetMaxLifetime 设置连接可以被重新使用的最大时间量

func SetMaxOpenConns

func SetMaxOpenConns(maxOpenConns int) Option

SetMaxOpenConns 设置打开连接到数据库的最大数量

func SetTrace

func SetTrace(t bool) Option

SetTrace 设置追踪调试

Jump to

Keyboard shortcuts

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