handler

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 12 Imported by: 1

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 InitializeWebsocket

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) AutoMigrate

func (d *Database) AutoMigrate() error

AutoMigrate 生成表结构

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) GetTableComment

func (d *Database) GetTableComment(database string, table string) (string, error)

func (*Database) GetTableFieldComment

func (d *Database) GetTableFieldComment(database string, table string) ([]Field, error)

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 Field

type Field struct {
	ColumnName    string `json:"column_name"`
	DataType      string `json:"data_type"`
	ColumnComment string `json:"column_comment"`
}

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 RedisClient

type RedisClient struct {
	*redis.Ring
	// contains filtered or unexported fields
}

RedisClient Redis客户端

var RedisHandler *RedisClient

RedisHandler Redis操作句柄

func NewRedis

func NewRedis(config dirver.RedisConfig) *RedisClient

NewRedis 实例化

func (*RedisClient) Delete

func (r *RedisClient) Delete(key string) *redis.IntCmd

func (*RedisClient) Get

func (r *RedisClient) Get(key string) *redis.StringCmd

func (*RedisClient) HDel

func (r *RedisClient) HDel(key string, field string) *redis.IntCmd

func (*RedisClient) HGet

func (r *RedisClient) HGet(key string, field string) *redis.StringCmd

func (*RedisClient) HGetAll

func (r *RedisClient) HGetAll(key string) *redis.MapStringStringCmd

HGetAll 获取全部hash

func (*RedisClient) HSet

func (r *RedisClient) HSet(key string, params map[string]any) *redis.IntCmd

HSet hash设置

func (*RedisClient) HSetNX

func (r *RedisClient) HSetNX(key string, field string, value any) *redis.BoolCmd

HSetNX hash设置

func (*RedisClient) Keys

func (r *RedisClient) Keys(pattern string) *redis.StringSliceCmd

func (*RedisClient) LPop

func (r *RedisClient) LPop(key string) *redis.StringCmd

func (*RedisClient) LPush

func (r *RedisClient) LPush(key string, values ...any) *redis.IntCmd

func (*RedisClient) Publish

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

Publish 发布

func (*RedisClient) RPop added in v0.2.4

func (r *RedisClient) RPop(key string) *redis.StringCmd

func (*RedisClient) Set

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

Set 字符串设置

func (*RedisClient) SetContext

func (r *RedisClient) SetContext(ctx context.Context)

SetContext 设置context

func (*RedisClient) SetNx

func (r *RedisClient) SetNx(key string, value any, expiration ...time.Duration) *redis.BoolCmd

SetNx 字符串设置

func (*RedisClient) Subscribe

func (r *RedisClient) Subscribe(channel string, callback SubscribeCallback) error

Subscribe 订阅

type SubscribeCallback

type SubscribeCallback func(message string)

SubscribeCallback 订阅回调

type Where

type Where any

Jump to

Keyboard shortcuts

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