gormx

package
v0.0.0-...-289f9df Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(db *gorm.DB, conditions ...any) (newDB *gorm.DB, err error)

func WithE2M

func WithE2M[PO any, Entity any](f func(dst *PO, src *Entity) error) func(*Repository[PO, Entity])

func WithIsolation

func WithIsolation(level sql.IsolationLevel) func(*sql.TxOptions)

func WithM2E

func WithM2E[PO any, Entity any](f func(dst *Entity, src *PO) error) func(*Repository[PO, Entity])

func WithPrefix

func WithPrefix(prefix string) func(*Module)

func WithReadOnly

func WithReadOnly(readOnly bool) func(*sql.TxOptions)

Types

type CommonField

type CommonField struct {
	SnowflakeID
	CreatedAt int64 `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime"`
}

type GormDBHolder

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

func NewGormDBHolder

func NewGormDBHolder(db *gorm.DB) *GormDBHolder

func (*GormDBHolder) Begin

func (d *GormDBHolder) Begin(sets ...func(*sql.TxOptions))

func (*GormDBHolder) BeginTx

func (d *GormDBHolder) BeginTx(sets ...func(*sql.TxOptions)) (tx *gorm.DB)

func (*GormDBHolder) Commit

func (d *GormDBHolder) Commit() error

func (*GormDBHolder) GetDB

func (d *GormDBHolder) GetDB() (db *gorm.DB)

func (*GormDBHolder) Rollback

func (d *GormDBHolder) Rollback() error

func (*GormDBHolder) Transaction

func (d *GormDBHolder) Transaction(f func() error, sets ...func(*sql.TxOptions)) (err error)

func (*GormDBHolder) TransactionTx

func (d *GormDBHolder) TransactionTx(f func(tx *gorm.DB) error, sets ...func(*sql.TxOptions)) (err error)

type JoinWhere

type JoinWhere struct {
	Direction  string
	Table      string
	Conditions string
	Where      []any
}

func (*JoinWhere) Apply

func (j *JoinWhere) Apply(db *gorm.DB) (*gorm.DB, error)

type Module

type Module struct {
	app.IsModule
	// contains filtered or unexported fields
}

func NewModule

func NewModule(opts ...func(*Module)) *Module

func (*Module) Init

func (m *Module) Init() (err error)

type Repository

type Repository[PO any, Entity any] struct {
	*GormDBHolder
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[PO any, Entity any](opts ...func(*Repository[PO, Entity])) *Repository[PO, Entity]

func (*Repository[PO, Entity]) Create

func (r *Repository[PO, Entity]) Create(entities ...*Entity) (err error)

func (*Repository[PO, Entity]) Delete

func (r *Repository[PO, Entity]) Delete(conditions ...any) (err error)

func (*Repository[PO, Entity]) E2M

func (r *Repository[PO, Entity]) E2M(dst *PO, src *Entity) (err error)

func (*Repository[PO, Entity]) First

func (r *Repository[PO, Entity]) First(conditions ...any) (entity *Entity, err error)

func (*Repository[PO, Entity]) List

func (r *Repository[PO, Entity]) List(conditions ...any) (list []*Entity, err error)

func (*Repository[PO, Entity]) M2E

func (r *Repository[PO, Entity]) M2E(dst *Entity, src *PO) (err error)

func (*Repository[PO, Entity]) Pagination

func (r *Repository[PO, Entity]) Pagination(offset, limit int, conditions ...any) (total int64, list []*Entity, err error)

func (*Repository[PO, Entity]) Update

func (r *Repository[PO, Entity]) Update(entity any, conditions ...any) (err error)

Update struct or map

type SnowflakeID

type SnowflakeID struct {
	ID uint64 `json:"id,string" gorm:"primaryKey;autoIncrement:false"`
}

func (*SnowflakeID) BeforeCreate

func (s *SnowflakeID) BeforeCreate(tx *gorm.DB) (err error)

type UnixTimestampMilli

type UnixTimestampMilli struct {
	CreatedAt int64 `json:"created_at" gorm:"autoCreateTime:milli"`
	UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime:milli"`
}

Jump to

Keyboard shortcuts

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