gorm.io/driver/mysql v1.5.7 gorm.io/gen v0.3.26 gorm.io/gorm v1.25.11

package datasource

import ( "fmt" "github.com/bwmarrin/snowflake" "gorm.io/gorm" )

type DbFieldPlugin struct{}

func (op *DbFieldPlugin) Name() string { return "dbFieldPlugin" }

func (op DbFieldPlugin) Initialize(db gorm.DB) (err error) { // 创建字段的时候雪花算法生成id _ = db.Callback().Create().Before("gorm:create").Replace("id", func(db *gorm.DB) { snowflake.NodeBits = 2 snowflake.StepBits = 10 node, _ := snowflake.NewNode(1) id := node.Generate() db.Statement.SetColumn("id", fmt.Sprintf("%d", id)) }) return }

------------------------------------------------------------------


package model

import ( "gorm.io/gorm" )

const TableNameFolder = "folder"

// Folder mapped from table type Folder struct { ID int64 gorm:"column:id;primaryKey;comment:表ID" json:"id" // 表ID UserID *int64 gorm:"column:user_id;comment:用户ID" json:"-" // 用户ID }

// TableName Folder's table name func (*Folder) TableName() string { return TableNameFolder }

func (u Folder) BeforeCreate(tx gorm.DB) (err error) { return }

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking