model

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("record not found")
	ErrInvalidID = errors.New("invalid id")
)

Functions

This section is empty.

Types

type BaseModel

type BaseModel[T any] struct {
	// contains filtered or unexported fields
}

BaseModel 泛型基础模型

func NewBaseModel

func NewBaseModel[T any](db *gorm.DB) *BaseModel[T]

NewBaseModel 创建泛型基础模型

func (*BaseModel[T]) DB

func (m *BaseModel[T]) DB() *gorm.DB

DB 获取底层DB

func (*BaseModel[T]) Delete

func (m *BaseModel[T]) Delete(ctx context.Context, tx *gorm.DB, condition map[string]any) error

Delete 删除数据

func (*BaseModel[T]) Exec

func (m *BaseModel[T]) Exec(ctx context.Context, tx *gorm.DB, sql string, args ...any) error

Exec 执行自定义SQL

func (*BaseModel[T]) FindAll

func (m *BaseModel[T]) FindAll(ctx context.Context, orderBy string, query string, args ...any) ([]*T, error)

FindAll 查询所有记录

func (*BaseModel[T]) FindCount

func (m *BaseModel[T]) FindCount(ctx context.Context, query string, args ...any) (int64, error)

FindCount 查询记录数

func (*BaseModel[T]) FindOne

func (m *BaseModel[T]) FindOne(ctx context.Context, condition map[string]any) (*T, error)

FindOne 根据条件查询单条

func (*BaseModel[T]) FindPage

func (m *BaseModel[T]) FindPage(ctx context.Context, page, pageSize int, orderBy string, query string, args ...any) ([]*T, int64, error)

FindPage 分页查询

func (*BaseModel[T]) Insert

func (m *BaseModel[T]) Insert(ctx context.Context, tx *gorm.DB, data *T) error

Insert 插入数据

func (*BaseModel[T]) Query

func (m *BaseModel[T]) Query(ctx context.Context, dest any, sql string, args ...any) error

Query 执行自定义查询

func (*BaseModel[T]) Transaction

func (m *BaseModel[T]) Transaction(ctx context.Context, fn func(tx *gorm.DB) error) error

Transaction 事务

func (*BaseModel[T]) Update

func (m *BaseModel[T]) Update(ctx context.Context, tx *gorm.DB, data *T) error

Update 更新数据

func (*BaseModel[T]) UpdateColumns

func (m *BaseModel[T]) UpdateColumns(ctx context.Context, tx *gorm.DB, condition map[string]any, columns map[string]any) error

UpdateColumns 更新指定列

type Geometry added in v0.0.4

type Geometry string

Geometry represents a MySQL geometry type stored as WKT (Well-Known Text) string When querying, use ST_AsText() to convert binary geometry to WKT format

func (Geometry) IsEmpty added in v0.0.4

func (g Geometry) IsEmpty() bool

IsEmpty returns true if the geometry is empty

func (*Geometry) Scan added in v0.0.4

func (g *Geometry) Scan(value any) error

Scan implements sql.Scanner interface

func (Geometry) String added in v0.0.4

func (g Geometry) String() string

String returns the WKT string representation

func (Geometry) Value added in v0.0.4

func (g Geometry) Value() (driver.Value, error)

Value implements driver.Valuer interface Returns WKT string for insert/update operations Note: For insert/update, you may need to use ST_GeomFromText() in raw SQL

type GeometryColumnsProvider added in v0.0.4

type GeometryColumnsProvider interface {
	GeometryColumns() []string
}

GeometryColumnsProvider interface for models with geometry columns Models implementing this interface will have their geometry columns automatically converted using ST_AsText() in queries

Jump to

Keyboard shortcuts

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