handler

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebsocketHandler *socket.WebSocket

Functions

func InitializeMysql

func InitializeMysql(config dirver.LinkParams) *gorm.DB

InitializeMysql 初始化数据库连接

func InitializeRedisPool

func InitializeRedisPool(config RedisConfig) *redis.Client

InitializeRedisPool 初始化redis连接池

func InitializeWebsocket added in v0.0.7

func InitializeWebsocket(pattern string, address string) *socket.WebSocket

Types

type CommonModel

type CommonModel struct {
	Id        int       `gorm:"column:id" json:"id"`
	CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}

CommonModel 数据库类型基类

type Database

type Database struct {
	Result any
	// contains filtered or unexported fields
}

Database 基础模型

var DBHandler *Database

DBHandler 数据库操作句柄

func NewDatabase

func NewDatabase(db *gorm.DB) *Database

NewDatabase 获取新的模型

func (*Database) Begin

func (d *Database) Begin() *gorm.DB

func (*Database) Create

func (d *Database) Create(model any) error

Create 创建数据

func (*Database) Delete

func (d *Database) Delete(model any) error

Delete 删除数据

func (*Database) DeleteByWhere

func (d *Database) DeleteByWhere(where any) error

DeleteByWhere 删除数据

func (*Database) ExecuteSql

func (d *Database) ExecuteSql(sql string, logMod ...bool) error

ExecuteSql 执行sql

func (*Database) Exist

func (d *Database) Exist(where Where) (bool, error)

Exist 检查数据是否存在

func (*Database) Find

func (d *Database) Find(id any) error

Find 根据id获取一条数据

func (*Database) First

func (d *Database) First(where Where, not ...Where) error

First 根据条件获取一条数据

func (*Database) Get

func (d *Database) Get(where ...any) error

Get 根据where条件查询数据

func (*Database) GetByPage

func (d *Database) GetByPage(pagination PaginationQuery, where any) PageData

GetByPage 分页查询数据

func (*Database) GetDb

func (d *Database) GetDb() *gorm.DB

GetDb 获取当前数据库连接

func (*Database) Save

func (d *Database) Save(model any) error

Save 保存修改的数据

func (*Database) SetMode

func (d *Database) SetMode() error

func (*Database) SetModel

func (d *Database) SetModel(executeModel any) *Database

SetModel 设置数据结果model

func (*Database) SetResult

func (d *Database) SetResult(resultModel any) *Database

SetResult 设置数据结果model

type ModelAction

type ModelAction interface {
	DataId() int
	TableName() string
}

type PageData

type PageData struct {
	PageInfo PageInfo
	DataList any
}

type PageInfo

type PageInfo struct {
	PrevPage   int
	CurrPage   int
	NextPage   int
	Pages      []int
	TotalCount int
	TotalPage  int
	Offset     int
	EndOffset  int
}

type PaginationQuery

type PaginationQuery struct {
	PageSize int
	PageNum  int
	// OrderBy 小写的字段名称
	OrderBy string
	// Order 默认是'desc', 可选的: 'desc', 'asc'
	Order string
}

PaginationQuery 分页查询

type PipAction

type PipAction func(pipeLiner redis.Pipeliner)

type RedisClient

type RedisClient struct {
	// contains filtered or unexported fields
}
var RedisHandler *RedisClient

RedisHandler Redis操作句柄

func NewRedis

func NewRedis(client *redis.Client) *RedisClient

NewRedis 实例化

func (*RedisClient) BLPop

func (r *RedisClient) BLPop(key string, timeout time.Duration) ([]string, error)

func (*RedisClient) Delete

func (r *RedisClient) Delete(key ...string) error

func (*RedisClient) Get

func (r *RedisClient) Get(key string) (bool, string, error)

func (*RedisClient) HGet

func (r *RedisClient) HGet(key, field string) (string, error)

func (*RedisClient) HGetAll

func (r *RedisClient) HGetAll(key string) (map[string]string, error)

func (*RedisClient) HSet

func (r *RedisClient) HSet(key string, values map[string]string) (int64, error)

HSet hash-set

func (*RedisClient) HSetNX

func (r *RedisClient) HSetNX(key, field string, value any) (bool, error)

func (*RedisClient) Keys

func (r *RedisClient) Keys(pattern string) ([]string, error)

func (*RedisClient) LPop

func (r *RedisClient) LPop(key string) (string, error)

func (*RedisClient) LPush

func (r *RedisClient) LPush(key string, value any) (int64, error)

func (*RedisClient) Publish

func (r *RedisClient) Publish(channel string, message any) (int64, error)

Publish 发布

func (*RedisClient) SelectDbAction

func (r *RedisClient) SelectDbAction(index int, action PipAction) (map[int]any, error)

func (*RedisClient) Set

func (r *RedisClient) Set(key string, value any, expiration time.Duration) error

Set 字符串设置

func (*RedisClient) SetNX

func (r *RedisClient) SetNX(key string, value any, expiration time.Duration) (bool, error)

func (*RedisClient) Subscribe

func (r *RedisClient) Subscribe(channel string) <-chan *redis.Message

Subscribe 订阅

type RedisConfig

type RedisConfig struct {
	Host       string `yaml:"host"`
	Port       int    `yaml:"port"`
	Db         int    `yaml:"db"`
	Password   string `yaml:"password"`
	MaxRetries int    `yaml:"maxRetries"`
}

RedisConfig 配置

type SubscribeData

type SubscribeData struct {
	Channel      string `json:"Channel"`
	Pattern      string `json:"Pattern"`
	Payload      string `json:"Payload"`
	PayloadSlice any    `json:"PayloadSlice"`
}

type Where

type Where any

Jump to

Keyboard shortcuts

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