database

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package database provides database client initialization.

Package database provides database client initialization.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheNotFound No hit cache
	ErrCacheNotFound = goredis.ErrRedisNotFound
)
View Source
var (
	ErrRecordNotFound = sgorm.ErrRecordNotFound
)

Functions

func CloseDB

func CloseDB() error

CloseDB close db

func CloseRedis

func CloseRedis() error

CloseRedis close redis

func GenerateOrderNo added in v1.3.6

func GenerateOrderNo(prefix string, snowId snowflake.ID) string

GenerateOrderNo 生成带有业务含义的订单号

func GetDB

func GetDB() *sgorm.DB

GetDB get db

func GetRedisCli

func GetRedisCli() *goredis.Client

GetRedisCli get redis client

func GetSequenceFromSnowId added in v1.3.6

func GetSequenceFromSnowId(id snowflake.ID) int64

GetSequenceFromSnowId 从雪花ID中提取序列号

func GetSnowId

func GetSnowId() snowflake.ID

func GetSnowNode

func GetSnowNode() *snowflake.Node

GetSnowNode get db

func GetTimeFromSnowId added in v1.3.6

func GetTimeFromSnowId(id snowflake.ID) time.Time

func InitCache

func InitCache(cType string)

InitCache initial cache

func InitDB

func InitDB()

InitDB connect database

func InitMysql

func InitMysql() *sgorm.DB

InitMysql connect mysql

func InitPostgresql

func InitPostgresql() *sgorm.DB

InitPostgresql connect postgresql

func InitRedis

func InitRedis()

InitRedis connect redis

func InitSnowNode

func InitSnowNode()

InitSnowNode connect redis

func InitSqlite

func InitSqlite() *sgorm.DB

InitSqlite connect sqlite

func ParseSnowId added in v1.3.6

func ParseSnowId(id snowflake.ID) map[string]int64

ParseSnowId 解析雪花ID的各个组成部分

Types

type CacheType

type CacheType struct {
	CType string          // cache type  memory or redis
	Rdb   *goredis.Client // if CType=redis, Rdb cannot be empty
}

CacheType cache type

func GetCacheType

func GetCacheType() *CacheType

GetCacheType get cacheType

type MqCfg added in v1.3.6

type MqCfg struct {
	ExchangeName    string        // 交换机名称
	NormalQueueName string        // 普通队列名称
	Url             string        // RabbitMQ连接URL
	DialTimeout     time.Duration // 连接超时时间
	IsDeadLetter    bool          // 是否启用死信队列
}

MqCfg 包含 RabbitMQ 配置信息

type RabbitMQClient added in v1.3.6

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

RabbitMQClient 封装RabbitMQ操作

func GetClient added in v1.3.6

func GetClient(ctx context.Context, cfg *MqCfg) (*RabbitMQClient, error)

GetClient 从连接池获取客户端

func (*RabbitMQClient) CloseConnection added in v1.3.6

func (c *RabbitMQClient) CloseConnection()

CloseConnection 关闭连接

func (*RabbitMQClient) Send added in v1.3.6

func (c *RabbitMQClient) Send(ctx context.Context, message string) error

Send 发送消息到RabbitMQ

Jump to

Keyboard shortcuts

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