db

package
v0.0.0-...-8d9547f Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPageSize 默认页大小
	DefaultPageSize = 10
)
View Source
var (
	// ErrContextNotFoundGorm 上下文不存在Gorm错误
	ErrContextNotFoundGorm = errors.New("上下文中没有获取到Gorm")
)

Functions

func FromContext

func FromContext(ctx context.Context) (*gormV1.DB, error)

FromContext 从上下文中获取Gorm

func FromGormV2Context

func FromGormV2Context(ctx context.Context) (*gormV2.DB, error)

FromGormV2Context 从上下文中获取Gorm

func LimitOffset

func LimitOffset(page int, perPage *int) int

LimitOffset ...

func NewContext

func NewContext(ctx context.Context, gdb *gormV1.DB) context.Context

NewContext 创建Gorm上下文

func NewGormV2Context

func NewGormV2Context(ctx context.Context, gdb *gormV2.DB) context.Context

NewGormV2Context 创建Gorm上下文

func SelectPageData

func SelectPageData(db *gormV1.DB, outData interface{}, primaryKey string, page, perPage int, sqlCmd string, sqlValues ...interface{}) (total int64, err error)

SelectPageData 查询翻页数据

Types

type DataBase

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

DataBase ...

func NewDataBase

func NewDataBase(conf DataBaseConfig, log nlog.Logger) *DataBase

NewDataBase ...

func (*DataBase) Close

func (db *DataBase) Close()

Close 关闭

func (*DataBase) Master

func (db *DataBase) Master() *gormV1.DB

Master 主

func (*DataBase) Slave

func (db *DataBase) Slave() *gormV1.DB

Slave 从

type DataBaseConfig

type DataBaseConfig struct {
	DBType        string
	MasterAddress string
	LogFlag       bool
	MaxOpen       int
	MaxIdle       int
	SlaveAddress  []string
}

DataBaseConfig ...

Jump to

Keyboard shortcuts

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