db

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 16 Imported by: 0

README

Db

go mysql service

useage

insert
SyncInsert(tab string, indexKey int64, data interface{})
ModInsert(db *sql.DB, tab string, data interface{}) (sql.Result, error)
select
SyncSelectRow(context *kernel.Context, tab string, indexKey int64, key ...interface{}) interface{}
SyncSelect(context *kernel.Context, tab string, indexKey int64, key ...interface{}) []interface{}
ModSelectRow(db *sql.DB, tab string, key []interface{}) interface{}
ModSelectAll(db *sql.DB, tab string, key []interface{}) []interface{}
update
SyncUpdate(tab string, indexKey int64, data interface{})
ModUpdate(db *sql.DB, tab string, data interface{}) (sql.Result, error)
delete
SyncDelete(tab string, indexKey int64, data interface{})
SyncDeletePKey(tab string, indexKey int64, pkey ...interface{})
ModDelete(db *sql.DB, tab string, data interface{}) (sql.Result, error)
ModDeletePKey(db *sql.DB, tab string, pkey []interface{}) (sql.Result, error)

Test see: db_test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Env = &env{
	ConnNum:     8,
	IsOpenCache: true,
}

Functions

func Encode

func Encode(v interface{}) string

func GetWhere

func GetWhere(def *TabDef, key ...interface{}) string

func GetWherePKey

func GetWherePKey(def *TabDef, data interface{}) string

Types

type Call

type Call func(pid *kernel.Pid, req interface{}) (bool, interface{})

type Config

type Config struct {
	Host    string
	Port    int
	User    string
	PWD     string
	ConnNum int
}

type Group

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

func GetGroup

func GetGroup(idx int) *Group

func Start

func Start(idx int, DBConfig Config, defSlice []*TabDef, dbName string, syncNum int, mode Mode) *Group

func (*Group) GetAllDef

func (g *Group) GetAllDef() []*TabDef

func (*Group) GetDef

func (g *Group) GetDef(tab string) *TabDef

func (*Group) ModDelete

func (g *Group) ModDelete(tab string, data interface{}) (sql.Result, error)

func (*Group) ModDeletePKey

func (g *Group) ModDeletePKey(tab string, pkey ...interface{}) (sql.Result, error)

func (*Group) ModInsert

func (g *Group) ModInsert(tab string, data interface{}) (sql.Result, error)

func (*Group) ModMultiInsert

func (g *Group) ModMultiInsert(tab string, data []interface{}) (sql.Result, error)

func (*Group) ModSelect

func (g *Group) ModSelect(tab string, fields []string, where string) [][]interface{}

func (*Group) ModSelectAll

func (g *Group) ModSelectAll(tab string, key ...interface{}) []interface{}

func (*Group) ModSelectAllWhere

func (g *Group) ModSelectAllWhere(tab string, where string) []interface{}

func (*Group) ModSelectRow

func (g *Group) ModSelectRow(tab string, key ...interface{}) interface{}

func (*Group) ModUpdate

func (g *Group) ModUpdate(tab string, data interface{}) (sql.Result, error)

func (*Group) ModUpdateFields

func (g *Group) ModUpdateFields(tab string, fields []string, data []interface{}, where string) (sql.Result, error)

func (*Group) SyncDelete

func (g *Group) SyncDelete(tab string, indexKey int64, data interface{})

func (*Group) SyncDeletePKey

func (g *Group) SyncDeletePKey(tab string, indexKey int64, pkey ...interface{})

func (*Group) SyncInsert

func (g *Group) SyncInsert(tab string, indexKey int64, data interface{})

func (*Group) SyncSelect

func (g *Group) SyncSelect(c Call, tab string, indexKey int64, key ...interface{}) []interface{}

查询多条记录

func (*Group) SyncSelectRow

func (g *Group) SyncSelectRow(c Call, tab string, indexKey int64, key ...interface{}) interface{}

查询单行

func (*Group) SyncUpdate

func (g *Group) SyncUpdate(tab string, indexKey int64, data interface{})

type Mode

type Mode int
const (
	MODE_NORMAL       Mode = iota + 1
	MODE_MULTI_INSERT      //适用是日志库,有批量插入缓存
)

type TabDef

type TabDef struct {
	Name       string
	Pkey       []string
	Keys       []string
	DataStruct interface{}
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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