g

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AND = iota
	OR
	ORDER
	SELECT
	GROUP
	JOIN
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMixin

type AuthMixin struct {
	CreateBy string `json:"createBy,omitempty" gorm:"column:create_by;type:varchar(100);default:null;comment:创建人"` // 创建人
	UpdateBy string `json:"updateBy,omitempty" gorm:"column:update_by;type:varchar(100);default:null;comment:更新人"` // 更新人
}

type BaseDao

type BaseDao[T any] struct {
	DB *gorm.DB
}

func (BaseDao[T]) Delete

func (dao BaseDao[T]) Delete(record *T) error

func (BaseDao[T]) DeleteByCondition

func (dao BaseDao[T]) DeleteByCondition(conditions *Conditions) error

func (BaseDao[T]) DeleteById

func (dao BaseDao[T]) DeleteById(id string) error

func (BaseDao[T]) DeleteByIds

func (dao BaseDao[T]) DeleteByIds(ids ...string) error

func (BaseDao[T]) DeleteHard

func (dao BaseDao[T]) DeleteHard(record *T) error

func (BaseDao[T]) DeleteHardByCondition

func (dao BaseDao[T]) DeleteHardByCondition(conditions *Conditions) error

func (BaseDao[T]) DeleteHardById

func (dao BaseDao[T]) DeleteHardById(id string) error

func (BaseDao[T]) DeleteHardByIds

func (dao BaseDao[T]) DeleteHardByIds(ids ...string) error

func (BaseDao[T]) Exist

func (dao BaseDao[T]) Exist(record *T) (bool, error)

func (BaseDao[T]) Insert

func (dao BaseDao[T]) Insert(record *T) error

func (BaseDao[T]) InsertBatch

func (dao BaseDao[T]) InsertBatch(records []*T, batch int) error

func (BaseDao[T]) InsertList

func (dao BaseDao[T]) InsertList(records []*T) error

func (BaseDao[T]) InsertOrSelect

func (dao BaseDao[T]) InsertOrSelect(record *T) error

func (BaseDao[T]) Save

func (dao BaseDao[T]) Save(record *T) error

func (BaseDao[T]) Select

func (dao BaseDao[T]) Select(record *T) ([]*T, error)

func (BaseDao[T]) SelectAll

func (dao BaseDao[T]) SelectAll() ([]*T, error)

func (BaseDao[T]) SelectByCondition

func (dao BaseDao[T]) SelectByCondition(conditions *Conditions) ([]*T, error)

func (BaseDao[T]) SelectById

func (dao BaseDao[T]) SelectById(id string) (*T, error)

func (BaseDao[T]) SelectByIds

func (dao BaseDao[T]) SelectByIds(ids ...string) ([]*T, error)

func (BaseDao[T]) SelectCount

func (dao BaseDao[T]) SelectCount(record *T) (int64, error)

func (BaseDao[T]) SelectCountByCondition

func (dao BaseDao[T]) SelectCountByCondition(conditions *Conditions) (int64, error)

func (BaseDao[T]) SelectDistinct

func (dao BaseDao[T]) SelectDistinct(conditions *Conditions) ([]*T, error)

func (BaseDao[T]) SelectOne

func (dao BaseDao[T]) SelectOne(record *T) (*T, error)

func (BaseDao[T]) SelectOneByConditions

func (dao BaseDao[T]) SelectOneByConditions(record *T, conditions *Conditions) (*T, error)

func (BaseDao[T]) SelectPage

func (dao BaseDao[T]) SelectPage(currentPage, pageSize int, sort string) (*Pagination[T], error)

func (BaseDao[T]) SelectPageByCondition

func (dao BaseDao[T]) SelectPageByCondition(currentPage, pageSize int, sort string, conditions *Conditions) (*Pagination[T], error)

func (BaseDao[T]) Update

func (dao BaseDao[T]) Update(record *T) error

func (BaseDao[T]) UpdateByCondition

func (dao BaseDao[T]) UpdateByCondition(record *T, conditions *Conditions) error

func (BaseDao[T]) UpdateSelective

func (dao BaseDao[T]) UpdateSelective(record *T, values any) error

func (BaseDao[T]) UpdateSelectiveByCondition

func (dao BaseDao[T]) UpdateSelectiveByCondition(record *T, conditions *Conditions) error

type BaseModel

type BaseModel struct {
	IdMixin
	PgTimeMixin
	AuthMixin
	Remarks string `json:"remarks,omitempty" gorm:"column:remarks;default:null;comment:备注"` // 备注
}

type BaseModelNoPg

type BaseModelNoPg struct {
	IdMixin
	TimeMixin
	AuthMixin
	Remarks string `json:"remarks,omitempty" gorm:"column:remarks;default:null;comment:备注"` // 备注
}

type BaseService

type BaseService[T any] struct {
	Dao Dao[T]
}

func (BaseService[T]) DeleteById

func (srv BaseService[T]) DeleteById(id string) error

func (BaseService[T]) DeleteByIds

func (srv BaseService[T]) DeleteByIds(ids ...string) error

func (BaseService[T]) FindAll

func (srv BaseService[T]) FindAll() ([]*T, error)

func (BaseService[T]) FindBy

func (srv BaseService[T]) FindBy(colName string, value any) (*T, error)

func (BaseService[T]) FindByCondition

func (srv BaseService[T]) FindByCondition(conditions *Conditions) ([]*T, error)

func (BaseService[T]) FindById

func (srv BaseService[T]) FindById(id string) (*T, error)

func (BaseService[T]) FindByIds

func (srv BaseService[T]) FindByIds(ids ...string) ([]*T, error)

func (BaseService[T]) Save

func (srv BaseService[T]) Save(entity *T) error

func (BaseService[T]) Saves

func (srv BaseService[T]) Saves(entities []*T) error

func (BaseService[T]) Update

func (srv BaseService[T]) Update(entity *T) error

type Conditions

type Conditions struct {
	// contains filtered or unexported fields
}

func NewConditions

func NewConditions() *Conditions

func (*Conditions) AndBetween

func (c *Conditions) AndBetween(field string, value1, value2 any) *Conditions

func (*Conditions) AndEqualTo

func (c *Conditions) AndEqualTo(field string, value any) *Conditions

func (*Conditions) AndGreaterThan

func (c *Conditions) AndGreaterThan(field string, value any) *Conditions

func (*Conditions) AndGreaterThanOrEqualTo

func (c *Conditions) AndGreaterThanOrEqualTo(field string, value any) *Conditions

func (*Conditions) AndILike

func (c *Conditions) AndILike(field string, value any) *Conditions

func (*Conditions) AndIn

func (c *Conditions) AndIn(field string, value any) *Conditions

func (*Conditions) AndIsNotNull

func (c *Conditions) AndIsNotNull(field string) *Conditions

func (*Conditions) AndIsNull

func (c *Conditions) AndIsNull(field string) *Conditions

func (*Conditions) AndLessThan

func (c *Conditions) AndLessThan(field string, value any) *Conditions

func (*Conditions) AndLessThanOrEqualTo

func (c *Conditions) AndLessThanOrEqualTo(field string, value any) *Conditions

func (*Conditions) AndLike

func (c *Conditions) AndLike(field string, value any) *Conditions

func (*Conditions) AndNotBetween

func (c *Conditions) AndNotBetween(field string, value1, value2 any) *Conditions

func (*Conditions) AndNotEqualTo

func (c *Conditions) AndNotEqualTo(field string, value any) *Conditions

func (*Conditions) AndNotIn

func (c *Conditions) AndNotIn(field string, value any) *Conditions

func (*Conditions) AndNotLike

func (c *Conditions) AndNotLike(field string, value any) *Conditions

func (*Conditions) Group

func (c *Conditions) Group(fields string) *Conditions

func (*Conditions) Joins

func (c *Conditions) Joins(joinCondition string) *Conditions

func (*Conditions) OrBetween

func (c *Conditions) OrBetween(field string, value1, value2 any) *Conditions

func (*Conditions) OrEqualTo

func (c *Conditions) OrEqualTo(field string, value any) *Conditions

func (*Conditions) OrGreaterThan

func (c *Conditions) OrGreaterThan(field string, value any) *Conditions

func (*Conditions) OrGreaterThanOrEqualTo

func (c *Conditions) OrGreaterThanOrEqualTo(field string, value any) *Conditions

func (*Conditions) OrILike

func (c *Conditions) OrILike(field string, value any) *Conditions

func (*Conditions) OrIn

func (c *Conditions) OrIn(field string, value any) *Conditions

func (*Conditions) OrIsNotNull

func (c *Conditions) OrIsNotNull(field string) *Conditions

func (*Conditions) OrIsNull

func (c *Conditions) OrIsNull(field string) *Conditions

func (*Conditions) OrLessThan

func (c *Conditions) OrLessThan(field string, value any) *Conditions

func (*Conditions) OrLessThanOrEqualTo

func (c *Conditions) OrLessThanOrEqualTo(field string, value any) *Conditions

func (*Conditions) OrLike

func (c *Conditions) OrLike(field string, value any) *Conditions

func (*Conditions) OrNotBetween

func (c *Conditions) OrNotBetween(field string, value1, value2 any) *Conditions

func (*Conditions) OrNotEqualTo

func (c *Conditions) OrNotEqualTo(field string, value any) *Conditions

func (*Conditions) OrNotLike

func (c *Conditions) OrNotLike(field string, value any) *Conditions

func (*Conditions) Order

func (c *Conditions) Order(fields string) *Conditions

func (*Conditions) OtNotIn

func (c *Conditions) OtNotIn(field string, value any) *Conditions

func (*Conditions) Select

func (c *Conditions) Select(fields string) *Conditions

func (*Conditions) To

func (c *Conditions) To(db *gorm.DB) *gorm.DB

type Dao

type Dao[T any] interface {
	Save(record *T) error                      // 插入或者更新
	Insert(record *T) error                    // 插入
	InsertList(records []*T) error             // 批量插入
	InsertBatch(records []*T, batch int) error // 批量插入, 自定义batch
	InsertOrSelect(record *T) error            // 插入或者获取第一个

	Delete(record *T) error                             // 删除
	DeleteHard(record *T) error                         // 硬删除
	DeleteById(id string) error                         // 根据id删除
	DeleteHardById(id string) error                     // 根据id硬删除
	DeleteByIds(ids ...string) error                    // 根据多个id批量删除
	DeleteHardByIds(ids ...string) error                // 根据多个id批量硬删除
	DeleteByCondition(conditions *Conditions) error     // 根据条件删除
	DeleteHardByCondition(conditions *Conditions) error // 根据条件硬删除

	Update(*T) error                                                    // 更新
	UpdateSelective(record *T, values any) error                        // 更新一个数据多列
	UpdateSelectiveByCondition(record *T, conditions *Conditions) error // 根据条件更新部分字段
	UpdateByCondition(record *T, conditions *Conditions) error          // 根据条件更新全部字段

	SelectById(id string) (*T, error)                                    // 根据id查询
	SelectByIds(ids ...string) ([]*T, error)                             // 根据多个id查询
	SelectOne(record *T) (*T, error)                                     // 根据记录查询一个
	SelectOneByConditions(record *T, conditions *Conditions) (*T, error) // 根据条件查询一个
	Select(record *T) ([]*T, error)                                      // 根据记录查询多个
	SelectAll() ([]*T, error)                                            // 查询所有
	SelectCount(record *T) (int64, error)                                // 查询数量
	SelectByCondition(conditions *Conditions) ([]*T, error)              // 根据条件查询
	SelectCountByCondition(conditions *Conditions) (int64, error)        // 根据条件查询数量
	SelectDistinct(conditions *Conditions) ([]*T, error)                 // 去重查询

	SelectPage(currentPage, pageSize int, sort string) (*Pagination[T], error)                                    // 分页查询
	SelectPageByCondition(currentPage, pageSize int, sort string, conditions *Conditions) (*Pagination[T], error) // 根据条件分页查询

	Exist(record *T) (bool, error) // 判断是否存在
}

type IdMixin

type IdMixin struct {
	ID string `json:"id" gorm:"primaryKey;column:id;type:varchar(32);comment:主键"` // 主键ID
}

func (*IdMixin) BeforeCreate

func (m *IdMixin) BeforeCreate(tx *gorm.DB) error

type Pagination

type Pagination[T any] struct {
	PageSize       int   `json:"pageSize"`       // 每页大小
	CurrentPage    int   `json:"currentPage"`    // 当前页
	TotalCount     int64 `json:"totalCount"`     // 总数
	TotalPages     int64 `json:"totalPages"`     // 总页数
	DataCollection []*T  `json:"dataCollection"` // 当前页数据
}

type PgTimeMixin

type PgTimeMixin struct {
	CreateTime Timestamp      `json:"createTime,omitempty" gorm:"autoCreateTime;column:create_time;type:timestamptz;comment:创建时间"` // 创建时间
	UpdateTime Timestamp      `json:"updateTime,omitempty" gorm:"autoUpdateTime;column:update_time;type:timestamptz;comment:更新时间"` // 更新时间
	DeleteTime gorm.DeletedAt `json:"-" gorm:"index;column:delete_time;type:timestamptz;comment:删除时间"`                             // 删除标记
}

type Service

type Service[T any] interface {
	Save(entity *T) error                                 // 保存
	Saves(entities []*T) error                            // 批量保存
	DeleteById(id string) error                           // 根据id删除单个
	DeleteByIds(ids ...string) error                      // 根据多个id删除
	Update(entity *T) error                               // 更新
	FindById(id string) (*T, error)                       // 根据id查找
	FindBy(colName string, value any) (*T, error)         // 根据某个字段查找唯一值
	FindByIds(ids ...string) ([]*T, error)                // 根据id查找多个
	FindByCondition(conditions *Conditions) ([]*T, error) // 根据条件查找
	FindAll() ([]*T, error)                               // 查找全部
}

type TimeMixin

type TimeMixin struct {
	CreateTime Timestamp      `json:"createTime,omitempty" gorm:"autoCreateTime;column:create_time;type:datetime;comment:创建时间"` // 创建时间
	UpdateTime Timestamp      `json:"updateTime,omitempty" gorm:"autoUpdateTime;column:update_time;type:datetime;comment:更新时间"` // 更新时间
	DeleteTime gorm.DeletedAt `json:"-" gorm:"index;column:delete_time;type:datetime;comment:删除时间"`                             // 删除标记
}

type Timestamp

type Timestamp time.Time

func (Timestamp) MarshalJSON

func (ts Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) Scan

func (ts *Timestamp) Scan(value interface{}) error

func (*Timestamp) UnmarshalJSON

func (ts *Timestamp) UnmarshalJSON(data []byte) error

func (Timestamp) Value

func (ts Timestamp) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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