orm

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PageFind

func PageFind[T any](db *gorm.DB, q page.Query) (data *page.Data[T], err error)

PageFind 分页查找

func Paginate

func Paginate(q page.Query) func(db *gorm.DB) *gorm.DB

Paginate 分页器

func SetTimeFormat added in v0.1.1

func SetTimeFormat(format string)

func SetTimeLocalZone added in v0.1.1

func SetTimeLocalZone(zone string)

Types

type LocalTime

type LocalTime time.Time

func (LocalTime) MarshalJSON

func (t LocalTime) MarshalJSON() ([]byte, error)

func (*LocalTime) Scan

func (t *LocalTime) Scan(v any) error

func (LocalTime) String

func (t LocalTime) String() string

func (*LocalTime) UnmarshalJSON

func (t *LocalTime) UnmarshalJSON(data []byte) (err error)

func (LocalTime) Value

func (t LocalTime) Value() (driver.Value, error)

type Model

type Model struct {
	ID        string         `json:"id" gorm:"primarykey"`
	CreatedAt LocalTime      `json:"createdAt"`
	UpdatedAt LocalTime      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}

Model ID 值使用UUID, 避免分布式环境下key冲突

LocalTime

1.可以通过配置指定格式 app.timeFormat
1.1.string -> time (指定根式序列化)
1.2.time -> string (指定根式反序列化)

func (*Model) BeforeCreate

func (u *Model) BeforeCreate(tx *gorm.DB) error

Jump to

Keyboard shortcuts

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