base

package
v0.0.0-...-83979ee Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package base 提供基础模型定义和通用数据库操作方法 创建者:Done-0 创建时间:2025-08-05

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	ID          int64   `gorm:"primaryKey;type:bigint" json:"id"`          // 主键(snowflake)
	GmtCreated  int64   `gorm:"type:bigint" json:"gmt_created"`            // 创建时间
	GmtModified int64   `gorm:"type:bigint" json:"gmt_modified"`           // 更新时间
	Ext         JSONMap `gorm:"type:json" json:"ext"`                      // 扩展字段
	Deleted     bool    `gorm:"type:boolean;default:false" json:"deleted"` // 逻辑删除
}

Base 包含模型通用字段

func (*Base) BeforeCreate

func (m *Base) BeforeCreate(db *gorm.DB) error

BeforeCreate 创建前设置时间戳和 ID 参数:

db: GORM数据库连接

返回值:

error: 操作过程中的错误

func (*Base) BeforeUpdate

func (m *Base) BeforeUpdate(db *gorm.DB) error

BeforeUpdate 更新前更新修改时间 参数:

db: GORM数据库连接

返回值:

error: 操作过程中的错误

type JSONMap

type JSONMap map[string]any

JSONMap 处理 JSON 类型字段

func (*JSONMap) Scan

func (j *JSONMap) Scan(value any) error

Scan 从数据库读取 JSON 数据 参数:

value: 数据库返回的值

返回值:

error: 操作过程中的错误

func (JSONMap) Value

func (j JSONMap) Value() (driver.Value, error)

Value 将 JSONMap 转换为 JSON 数据存储到数据库 返回值:

driver.Value: 数据库驱动值
error: 操作过程中的错误

Jump to

Keyboard shortcuts

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