gormx

package module
v0.0.0-...-0cb8732 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 14 Imported by: 0

README

gormx

gorm扩展库

安装

go get -u github.com/qwxingzhe/gormx

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count[TBase any](orm Orm, maps map[string]interface{}) (count int64)

func CreateOne

func CreateOne[TBase, TFormat any](orm Orm, data TBase) (info TFormat)

func CreateOneSimp

func CreateOneSimp[TBase any](orm Orm, data TBase) TBase

func Delete

func Delete[Tm any](orm Orm, uc UpdateConfig) (err error)

func Format

func Format[T any](info T) T

func FormatList

func FormatList(originList interface{}, formatFunc interface{}) []interface{}

FormatList 格式化列表

func FormatListSimp

func FormatListSimp[TBase, TFormat any](baseList []TBase, formatEvery bool) []TFormat

func GetList

func GetList[TBase, TFormat any](orm Orm, c ListConfig) []TFormat

GetList 简单获取查询DB格式化后的列表

func GetListSimp

func GetListSimp[TBase any](orm Orm, c ListConfig) []TBase

func GetOne

func GetOne[TBase, TFormat any](orm Orm, where map[string]interface{}) (info TFormat)

func GetOneSimp

func GetOneSimp[TBase any](orm Orm, where map[string]interface{}) (info TBase)

func KeyList

func KeyList(originList interface{}, key string) []interface{}

KeyList 获取list中指定key数组

func Update

func Update[Tm, Tf any](orm Orm, uc UpdateConfig, SetFunc func(info Tm) (Tm, error)) (info2 Tf, err error)

func UpdateOne

func UpdateOne[TFormat, TBase any](orm Orm, data TBase) (info TFormat)

func UpdateOneSimp

func UpdateOneSimp[TBase any](orm Orm, data TBase) TBase

Types

type BaseModel

type BaseModel struct {
	Id        int64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

type BaseModelOnlyId

type BaseModelOnlyId struct {
	Id int64 `gorm:"primary_key"`
}

type BaseModelWithoutDeletedAt

type BaseModelWithoutDeletedAt struct {
	Id        int64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type BaseModelWithoutDeletedCreatedAt

type BaseModelWithoutDeletedCreatedAt struct {
	Id        int64 `gorm:"primary_key"`
	UpdatedAt time.Time
}

type BaseModelWithoutDeletedUpdatedAt

type BaseModelWithoutDeletedUpdatedAt struct {
	Id        int64 `gorm:"primary_key"`
	CreatedAt time.Time
}

type FilterConfig

type FilterConfig struct {
	Order    string
	MaxLimit int
}

type IBaseModel

type IBaseModel interface {
	Format() interface{}
}

type ListConfig

type ListConfig struct {
	Filter       map[string]interface{}
	FilterConfig FilterConfig
	FormatEvery  bool
}

type MysqlConfig

type MysqlConfig struct {
	DBAddress      string `yaml:"DBAddress" json:"DBAddress"`
	DBUserName     string `yaml:"DBUserName" json:"DBUserName"`
	DBPassword     string `yaml:"DBPassword" json:"DBPassword"`
	DBDatabaseName string `yaml:"DBDatabaseName" json:"DBDatabaseName"`
	DBTablePrefix  string `yaml:"DBTablePrefix" json:"DBTablePrefix"`
	DBMaxOpenConns int    `yaml:"DBMaxOpenConns" json:"DBMaxOpenConns"`
	DBMaxIdleConns int    `yaml:"DBMaxIdleConns" json:"DBMaxIdleConns"`
	DBMaxLifeTime  int64  `yaml:"DBMaxLifeTime" json:"DBMaxLifeTime"`
	SingularTable  bool   `yaml:"SingularTable" json:"SingularTable"`
}

type Orm

type Orm struct {
	// gorm实例
	GormDb *gorm.DB
	// 默认排序方式
	DefaultOrder string
	// contains filtered or unexported fields
}

func GetOrm

func GetOrm() Orm

func InitOrm

func InitOrm(mysqlConfig MysqlConfig, cache cache.Interface) Orm

InitOrm 初始化orm单例对象

func (Orm) Begin

func (o Orm) Begin() Orm

Begin 开始事务

func (Orm) ClearTempData

func (o Orm) ClearTempData() Orm

func (Orm) Commit

func (o Orm) Commit()

Commit 提交事务

func (Orm) Count

func (o Orm) Count(list interface{}, maps map[string]interface{}) (count int64)

func (Orm) Debug

func (o Orm) Debug() Orm

func (Orm) Delete

func (o Orm) Delete(info interface{})

Delete 删除记录

func (Orm) Find

func (o Orm) Find(list interface{}, maps map[string]interface{})

Find 查询记录列表

func (Orm) FindPage

func (o Orm) FindPage(pageSize int, page int, list interface{}, maps map[string]interface{}) PageInfo

FindPage 查询记录列表

func (Orm) First

func (o Orm) First(info interface{}, maps map[string]interface{})

First 查询一条记录

func (Orm) GetInfo

func (o Orm) GetInfo(info interface{}, id int64) error

GetInfo 获取详情

func (Orm) GetInfoByKey

func (o Orm) GetInfoByKey(info interface{}, key string, value interface{})

GetInfoByKey 通过指定的key、value获取数据

func (Orm) GetInfoByKeyLike

func (o Orm) GetInfoByKeyLike(info interface{}, key string, value interface{})

GetInfoByKeyLike 通过模糊匹配获取数据

func (Orm) In

func (o Orm) In(key string, values []interface{}) Orm

func (Orm) Joins

func (o Orm) Joins(query string, args ...interface{}) Orm

func (Orm) Limit

func (o Orm) Limit(limit int) Orm

func (Orm) Order

func (o Orm) Order(v interface{}) Orm

func (Orm) Original

func (o Orm) Original(f func(*gorm.DB) *gorm.DB) Orm

func (Orm) Rollback

func (o Orm) Rollback()

Rollback 回滚事务

func (Orm) Save

func (o Orm) Save(info interface{}) error

Save 保存记录

func (Orm) Select

func (o Orm) Select(fields string) Orm

func (Orm) SetDefaultOrder

func (o Orm) SetDefaultOrder(s string) Orm

func (Orm) Table

func (o Orm) Table(name string, args ...interface{}) Orm

func (Orm) Unscoped

func (o Orm) Unscoped() Orm

func (Orm) Where

func (o Orm) Where(maps map[string]interface{}) Orm

type PageInfo

type PageInfo struct {
	// 当前页面
	CurrentPage int `json:"current_page"`
	// 页面记录条数
	PageSize int `json:"page_size"`
	// 总记录数
	Total int64 `json:"total"`
}

type PageResult

type PageResult struct {
	List     interface{} `json:"list"`
	PageInfo PageInfo    `json:"page_info"`
}

func FindPage

func FindPage[TBase, TFormat any](o Orm, pageSize int, pageStr interface{}, c *ListConfig) PageResult

FindPage 查询记录列表

type RedisConfig

type RedisConfig struct {
	Addr     string
	DB       int
	Password string
}

type UpdateConfig

type UpdateConfig struct {
	GetFilter map[string]interface{}
	EmptyMsg  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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