gormx

package
v0.0.0-...-8210b9c Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterCreate

func AfterCreate(db *gorm.DB)

AfterCreate 全局钩子:创建后

func AfterDelete

func AfterDelete(db *gorm.DB)

AfterDelete 全局钩子:删除后

func AfterQuery

func AfterQuery(db *gorm.DB)

func AfterSave

func AfterSave(db *gorm.DB)

AfterSave 全局钩子:保存后

func AfterUpdate

func AfterUpdate(db *gorm.DB)

AfterUpdate 全局钩子:更新后

func IsUniqueError

func IsUniqueError(err error) bool

IsUniqueError 是否是唯一索引错误

func Must

func Must(cs ...config.Config)

Must initialize the database

func NotFound

func NotFound(err error) bool

NotFound 判断是否未未找到错误

Types

type BaseDAO

type BaseDAO interface {
	Model() *gorm.DB
}

type DBManager

type DBManager struct {
	sync.RWMutex
	Mysql      *gorm.DB
	Postgres   *gorm.DB
	ClickHouse *gorm.DB
}

DBManager gorm db manager

var (
	Engine *DBManager
)

func NewDBManager

func NewDBManager() *DBManager

func (*DBManager) CloseAll

func (dm *DBManager) CloseAll() error

CloseAll close all connections

func (*DBManager) Initialize

func (dm *DBManager) Initialize(cs ...config.Config) error

Initialize initialize the database

type GlobalHooks

type GlobalHooks struct{}

type Model

type Model struct {
	CreatedAt int64                 `json:"created_at"`
	UpdatedAt int64                 `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `json:"deleted_at" gorm:"default:0" `
}

Model 基础模型

type OperationBaseModel

type OperationBaseModel struct {
	OperationTime int64  `gorm:"column:operation_time" json:"operation_time"` // 操作时间,记录修改的时间
	OperatorID    int64  `gorm:"column:operator_id" json:"operator_id"`       // 操作人ID,记录是由谁修改的
	Operator      string `gorm:"column:operator" json:"operator" `            // 操作人,记录是由谁修改的
}

func (*OperationBaseModel) BeforeSave

func (base *OperationBaseModel) BeforeSave(tx *gorm.DB) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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