dbx

package
v0.0.0-...-a8d7d85 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoMessageFieldCreatedAt = "created_at"
	ProtoMessageFieldUpdatedAt = "updated_at"
	ProtoMessageFieldDeletedAt = "deleted_at"
)
View Source
const DefaultLimit uint32 = 2000
View Source
const DefaultOffset uint32 = 0
View Source
const MaxLimit uint32 = 100000

Variables

This section is empty.

Functions

func GetNotFoundErr

func GetNotFoundErr(err error) *errorx.Error

func IsNotFoundErr

func IsNotFoundErr(err error, errCode int32) bool

IsNotFoundErr returns true if err is an *Error and its ErrorCode matches ErrCodeRecordNotFoundSys or errCode.

func ScopeTxGo

func ScopeTxGo(db *gorm.DB, callbacks ...TxCallback) error

func TxGo

func TxGo(db *gorm.DB, executes ...TxHandler) error

Types

type GenerateIDFunc

type GenerateIDFunc func(ctx context.Context, cnt int) []uint64

type ModelBase

type ModelBase interface {
	ProtoReflect() protoreflect.Message
	GetId() uint64
}

type OrderColumn

type OrderColumn struct {
	Field   string
	Desc    bool
	Reorder bool
}

type ProtoDeletedAt

type ProtoDeletedAt interface {
	GetDeletedAt() uint32
}

type ProtoUpsertedAt

type ProtoUpsertedAt interface {
	ProtoReflect() protoreflect.Message
	GetCreatedAt() uint32
	GetUpdatedAt() uint32
	ProtoDeletedAt
}

type QueryOpts

type QueryOpts struct {
	Selects   []string
	Where     map[string]interface{}
	Between   map[string][2]interface{}
	Like      map[string]string
	Or        map[string]interface{}
	OrLike    map[string]string
	OrBetween map[string][2]interface{}

	GroupBys []string
	OrderBys []OrderColumn
	// contains filtered or unexported fields
}

type Scope

type Scope struct {
	*gorm.DB

	NotFoundErr error
	// contains filtered or unexported fields
}

func NewScope

func NewScope(db *gorm.DB, model interface{}) *Scope

func NewScopeOfPure

func NewScopeOfPure(db *gorm.DB, model interface{}) *Scope

func (*Scope) Association

func (s *Scope) Association(value string) *Scope

func (*Scope) Between

func (s *Scope) Between(field string, arg1, arg2 interface{}) *Scope

func (*Scope) Count

func (s *Scope) Count() (total int64, err error)

func (*Scope) Create

func (s *Scope) Create(v interface{}) error

func (*Scope) CreateInBatches

func (s *Scope) CreateInBatches(values interface{}, batchSize int) error

CreateInBatches Insert data in batches after splitting data according to batchSize

func (*Scope) Delete

func (s *Scope) Delete(conds ...interface{}) error

func (*Scope) Eq

func (s *Scope) Eq(field string, arg interface{}) *Scope

func (*Scope) Exist

func (s *Scope) Exist(conds ...interface{}) (bool, error)

func (*Scope) Find

func (s *Scope) Find(dest interface{}, conds ...interface{}) error

func (*Scope) First

func (s *Scope) First(dest interface{}, conds ...interface{}) error

func (*Scope) Group

func (s *Scope) Group(name string) *Scope

func (*Scope) Groups

func (s *Scope) Groups(names ...string) *Scope

func (*Scope) Gt

func (s *Scope) Gt(field string, arg interface{}) *Scope

func (*Scope) Gte

func (s *Scope) Gte(field string, arg interface{}) *Scope

func (*Scope) HandlePaginate

func (s *Scope) HandlePaginate(opt *paging.Paginate) *paging.Paginate

func (*Scope) Having

func (s *Scope) Having(query interface{}, args ...interface{}) *Scope

func (*Scope) IgnoreNotFoundErr

func (s *Scope) IgnoreNotFoundErr() *Scope

func (*Scope) In

func (s *Scope) In(field string, values interface{}) *Scope

func (*Scope) Joins

func (s *Scope) Joins(query string, args ...interface{}) *Scope

func (*Scope) Like

func (s *Scope) Like(field string, value string) *Scope

func (*Scope) LikePrefix

func (s *Scope) LikePrefix(field string, value string) *Scope

func (*Scope) Limit

func (s *Scope) Limit(limit int) *Scope

func (*Scope) Lt

func (s *Scope) Lt(field string, arg interface{}) *Scope

func (*Scope) Lte

func (s *Scope) Lte(field string, arg interface{}) *Scope

func (*Scope) MultiOr

func (s *Scope) MultiOr(opts map[string]interface{}) *Scope

func (*Scope) MultiOrLike

func (s *Scope) MultiOrLike(opts map[string]string, isPrefix bool) *Scope

func (*Scope) Ne

func (s *Scope) Ne(field string, arg interface{}) *Scope

Ne :Where("field != ?", arg)

func (*Scope) NotBetween

func (s *Scope) NotBetween(field string, arg1, arg2 interface{}) *Scope

func (*Scope) NotIn

func (s *Scope) NotIn(field string, values interface{}) *Scope

func (*Scope) Offset

func (s *Scope) Offset(offset int) *Scope

func (*Scope) Omit

func (s *Scope) Omit(value ...string) *Scope

func (*Scope) Or

func (s *Scope) Or(query interface{}, args ...interface{}) *Scope

func (*Scope) Order

func (s *Scope) Order(value string) *Scope

Order db.Order("name DESC")

func (*Scope) Orders

func (s *Scope) Orders(values ...OrderColumn) *Scope

func (*Scope) PaginateQuery

func (s *Scope) PaginateQuery(opt *paging.Paginate, list interface{}) (*paging.Paginate, error)

func (*Scope) Preload

func (s *Scope) Preload(query string, args ...interface{}) *Scope

func (*Scope) Query

func (s *Scope) Query(opts *QueryOpts) *Scope

func (*Scope) ResetSysDateTimeField

func (s *Scope) ResetSysDateTimeField(v interface{})

ResetSysDateTimeField To prevent someone from passing in these three fields by mistake, this method is provided to reset

func (*Scope) Select

func (s *Scope) Select(fields ...string) *Scope

func (*Scope) SetGenerateIDFunc

func (s *Scope) SetGenerateIDFunc(idFunc GenerateIDFunc) *Scope

func (*Scope) SetNotFoundErr

func (s *Scope) SetNotFoundErr(notFoundErrCode int32) *Scope

func (*Scope) Unscoped

func (s *Scope) Unscoped() *Scope

func (*Scope) Update

func (s *Scope) Update(v interface{}, conds ...interface{}) error

Update updates attributes using callbacks. values must be a struct or map.

func (*Scope) Where

func (s *Scope) Where(query interface{}, args ...interface{}) *Scope

type TxCallback

type TxCallback func() (model interface{}, execute func(scope *Scope) error)

type TxHandler

type TxHandler func(tx *gorm.DB) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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