xdb

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmptyVal    = ""
	PartOnlyOne = 1
)
View Source
const (
	// MYSQL dbType
	MYSQL = "mysql"
	// PG dbType
	PG = "postgres"
)

Variables

This section is empty.

Functions

func DB

func DB() *gorm.DB

DB 获取数据库链接

func GetAutoSliceDB added in v1.2.6

func GetAutoSliceDB(db *gorm.DB, userId int64, sf SP) *gorm.DB

GetAutoSliceDB 获取自动分表

func InitQpsDB added in v1.2.6

func InitQpsDB(limit int, interval time.Duration)

InitQpsDB 初始化同步等待QPS DB

func OpenMysqlDB

func OpenMysqlDB(dbType string, dbUrl string, config *gorm.Config, maxIdleConns, maxOpenConns int, models ...interface{}) (instance *gorm.DB, err error)

OpenMysqlDB gorm v2 dbUrl = username:password@tcp(localhost:3306)/db_name?charset=utf8mb4&parseTime=True&loc=Local

func QpsDB added in v1.3.3

func QpsDB() *gorm.DB

QpsDB 获取DB对象,若超时则返回nil

func SetMainDB added in v1.4.4

func SetMainDB(main *gorm.DB, DSN string)

SetMainDB 设置主DB

Types

type Consistent added in v1.4.6

type Consistent struct {

	//虚拟节点个数,用来增加hash的平衡性
	VirtualNode int
	//map 读写锁
	sync.RWMutex
	// contains filtered or unexported fields
}

Consistent 创建结构体保存一致性hash信息

func NewConsistent added in v1.4.6

func NewConsistent() *Consistent

NewConsistent 创建一致性hash算法结构体,设置默认节点数量

func (*Consistent) Add added in v1.4.6

func (c *Consistent) Add(element string)

Add 向hash环中添加节点

func (*Consistent) Get added in v1.4.6

func (c *Consistent) Get(name string) (string, error)

Get 根据数据标示获取最近的服务器节点信息

func (*Consistent) Remove added in v1.4.6

func (c *Consistent) Remove(element string)

Remove 删除一个节点

type SP added in v1.2.6

type SP struct {
	Value  interface{}
	Part   int64  // 用户ID取余分表
	ByDate string // 通过日期2022-01-01分表,按月,按日
}

Jump to

Keyboard shortcuts

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