gorm

package
v0.0.0-...-9a7220d Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB(dbName string) *gorm.DB

Types

type BaseDao

type BaseDao[M any, ID comparable] struct {
	// contains filtered or unexported fields
}

func NewBaseDao

func NewBaseDao[M any, ID comparable](dbName, tableName, pkName string) *BaseDao[M, ID]

func (*BaseDao[M, ID]) BatchCreate

func (dao *BaseDao[M, ID]) BatchCreate(ctx context.Context, ms []*M) error

func (*BaseDao[M, ID]) Create

func (dao *BaseDao[M, ID]) Create(ctx context.Context, m *M) error

func (*BaseDao[M, ID]) DB

func (dao *BaseDao[M, ID]) DB(ctx context.Context) *gorm.DB

func (*BaseDao[M, ID]) DeleteByWhere

func (dao *BaseDao[M, ID]) DeleteByWhere(ctx context.Context, where string, args []any) (int64, error)

func (*BaseDao[M, ID]) FindListByWhere

func (dao *BaseDao[M, ID]) FindListByWhere(ctx context.Context, query string, args []any, columns ...string) ([]*M, error)

func (*BaseDao[M, ID]) FindOneByWhere

func (dao *BaseDao[M, ID]) FindOneByWhere(ctx context.Context, where string, args []any, columns ...string) (*M, bool, error)

func (*BaseDao[M, ID]) GetByPk

func (dao *BaseDao[M, ID]) GetByPk(ctx context.Context, id ID) (*M, bool, error)

func (*BaseDao[M, ID]) Transaction

func (dao *BaseDao[M, ID]) Transaction(ctx context.Context, fn func(ctx context.Context, tx *gorm.DB) error) error

func (*BaseDao[M, ID]) UpdateByWhere

func (dao *BaseDao[M, ID]) UpdateByWhere(ctx context.Context, where string, args []any, data any, columns ...string) (int64, error)

type Dao

type Dao[M any, ID comparable] interface {
	DB(ctx context.Context) *gorm.DB
	Transaction(ctx context.Context, fn func(ctx context.Context, tx *gorm.DB) error) error

	Create(ctx context.Context, data any) error // 支持单条和批量
	UpdateByWhere(ctx context.Context, where string, args []any, data any, columns ...string) error
	DeleteByWhere(ctx context.Context, where string, args []any) error
	GetByPk(ctx context.Context, id ID) (*M, bool, error)
	FindOneByWhere(ctx context.Context, where string, args []any, columns ...string) (*M, bool, error)
	FindListByWhere(ctx context.Context, where string, args []any, columns ...string) ([]*M, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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