database

package
v0.0.0-...-ee0865d Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(db *Info)

func RegisterTable

func RegisterTable(db *Table)

func Remove

func Remove(name string)

func RemoveTable

func RemoveTable(name string)

func UpdateName

func UpdateName(cache map[string]string)

Types

type CacheType

type CacheType int

缓存方式

const (
	// 不使用
	CacheType_无 CacheType = iota
	// 存储在本地数据库中
	CacheType_本地
	// 存储在会话中
	CacheType_会话
	// 存储在一次请求的上下文中
	CacheType_请求
	// 存储在全局缓存中
	CacheType_全局
)

type DatabaseType

type DatabaseType int
const (
	DatabaseType_Mongo DatabaseType = iota + 1
	DatabaseType_Mysql
)

func (DatabaseType) String

func (db DatabaseType) String() string

type Group

type Group struct {
	Keys    []Ident
	SubKeys []Ident
}

type IDO

type IDO interface {
}

type ITableIndex

type ITableIndex interface {
}

==============================================================

type Ident

type Ident string

func NewIdentByInt

func NewIdentByInt(num int) (id Ident)

func NewIdentByString

func NewIdentByString(val string) (id Ident)

func (Ident) GetSnowflake

func (x Ident) GetSnowflake() int64

func (Ident) String

func (x Ident) String() string

func (Ident) Valid

func (x Ident) Valid() (err error)

type Info

type Info struct {
	//
	Name string
	// 数据库的地址
	Addr string
	// 类型
	Type DatabaseType
	// contains filtered or unexported fields
}

func Get

func Get(name string) (db *Info, ok bool)

func (*Info) CloseConnection

func (c *Info) CloseConnection(conn *mongo.Client) (err error)

func (*Info) GetConnection

func (c *Info) GetConnection() (conn *mongo.Client, err error)

从连接池中获取地址为[addr]的连接

func (*Info) Ping

func (c *Info) Ping() (err error)

func (*Info) PutConnection

func (c *Info) PutConnection(conn *mongo.Client)

归还[conn]

func (*Info) String

func (c *Info) String() string

type Table

type Table struct {
	// 表名
	Name string
	// 数据库信息的
	Database string
	// 数据库的命名
	// 用于游戏服务器可根据渠道命名,便于物理分离时的数据迁移
	// ${Database}_${_channel}
	DatabaseName string
	// 分表模式
	Mode TableMode
	// 主键
	PrimaryKey string
	// 分表键
	SubKey string
	// 新建
	Parser func(map[string]interface{}) (interface{}, error)
	// 索引
	Indexs map[int]interface{}
	// 缓存方式
	CacheType CacheType
	// 缓存持续时间
	CacheExpired time.Duration
	// 启用redis缓存
	EnableRedis bool
}

func GetTable

func GetTable(name string) (db *Table, ok bool)

func (*Table) ByShard

func (t *Table) ByShard(key Ident) string

获取分片表名, key为分表键

func (*Table) ByTime

func (t *Table) ByTime(key Ident) string

获取按照时间分表的表名

func (*Table) GroupByShard

func (t *Table) GroupByShard(ids []Ident, subKeys []Ident) (r map[string]*Group)

id集合按照shard的方式分组后的映射 键为表名,值为分组后的id集合

func (*Table) GroupByTime

func (t *Table) GroupByTime(ids []Ident, subKeys []Ident) (r map[string]*Group)

id集合按照time的方式分组后的映射 键值为表名,值为分组后的id集合

func (*Table) HasCache

func (t *Table) HasCache() bool

func (*Table) Long

func (t *Table) Long(key Ident) (name string)

func (*Table) Short

func (t *Table) Short() string

func (*Table) Valid

func (t *Table) Valid() (err error)

type TableMode

type TableMode int
const (
	TableMode_无 TableMode = iota
	// 需要设置分表键
	TableMode_按时间
	// 需要设置分表键
	TableMode_按分表键
)

type Time

type Time int

func (Time) Valid

func (x Time) Valid() (err error)

Jump to

Keyboard shortcuts

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