stdao

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

stdao

Generic DAO layer with gorm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Std

type Std[T any] struct {
	// contains filtered or unexported fields
}

func Create

func Create[T any](m T) *Std[T]

func (*Std[T]) Begin

func (s *Std[T]) Begin() *Std[T]

Begin a transaction with any transaction options opts

func (*Std[T]) Commit

func (s *Std[T]) Commit() (result *gorm.DB)

Commit the transaction

func (*Std[T]) Count

func (s *Std[T]) Count() (count int64)

func (*Std[T]) Create

func (s *Std[T]) Create(model T, tx ...*gorm.DB) (result *gorm.DB)

Create the model to the database.

func (*Std[T]) DB

func (s *Std[T]) DB() *gorm.DB

DB return the

func (*Std[T]) Debug

func (s *Std[T]) Debug() *Std[T]

Debug start debug mode.

func (*Std[T]) Delete

func (s *Std[T]) Delete(model T, tx ...*gorm.DB) (result *gorm.DB)

Delete the model from the database.

func (*Std[T]) Find

func (s *Std[T]) Find(model T, tx ...*gorm.DB) (result *gorm.DB)

Find the model from the database.

func (*Std[T]) First

func (s *Std[T]) First(model T, tx ...*gorm.DB) (result *gorm.DB)

First the model from the database.

func (*Std[T]) Get

func (s *Std[T]) Get(key string) (interface{}, bool)

Get value with key from current db instance's context.

func (*Std[T]) Init

func (s *Std[T]) Init(db *gorm.DB) (err error)

func (*Std[T]) List

func (s *Std[T]) List(where []clause.Expression, order []clause.OrderByColumn, page page.Paginate, tx ...*gorm.DB) (list []T, result *gorm.DB)

func (*Std[T]) Pluck added in v1.2.0

func (s *Std[T]) Pluck(column string, dest interface{}) *gorm.DB

Pluck queries a single column from a model, returning in the slice dest. E.g.: var ages []int64 db.Model(&users).Pluck("age", &ages)

func (*Std[T]) Rollback

func (s *Std[T]) Rollback() (result *gorm.DB)

Rollback the transaction

func (*Std[T]) Save

func (s *Std[T]) Save(model T, tx ...*gorm.DB) (result *gorm.DB)

Save the model to the database.

func (*Std[T]) Session

func (s *Std[T]) Session(session *gorm.Session) *Std[T]

Session create new db session

func (*Std[T]) Set

func (s *Std[T]) Set(key string, value interface{}) *Std[T]

Set value with key into current db instance's context.

func (*Std[T]) Transaction

func (s *Std[T]) Transaction(fc func(tx *Std[T]) error) (err error)

Transaction start a transaction as a block, return any error will rollback the transaction

func (*Std[T]) Update

func (s *Std[T]) Update(model T, tx ...*gorm.DB) (result *gorm.DB)

Update the model to the database.

func (*Std[T]) Updates

func (s *Std[T]) Updates(model T, m map[string]interface{}, tx ...*gorm.DB) (result *gorm.DB)

func (*Std[T]) Use

func (s *Std[T]) Use(plugin gorm.Plugin) (err error)

func (*Std[T]) Where added in v1.2.0

func (s *Std[T]) Where(query any, args ...any) (result *gorm.DB)

func (*Std[T]) WhereByPredicateModel added in v1.2.0

func (s *Std[T]) WhereByPredicateModel(predicateModel T) (result *gorm.DB)

func (*Std[T]) WithCtx

func (s *Std[T]) WithCtx(ctx context.Context) *Std[T]

func (*Std[T]) WithMigrator

func (s *Std[T]) WithMigrator(mf func(db *gorm.DB) error)

type StdWithCache

type StdWithCache[T any] struct {
	Std[T]
	cache.StatsAccessor
}

func CreateWithCache

func CreateWithCache[T any](m T) StdWithCache[T]

func (*StdWithCache[T]) Init

func (s *StdWithCache[T]) Init(db *gorm.DB, cacheConfig *config.CacheConfig) (err error)

func (*StdWithCache[T]) Pluck added in v1.2.0

func (s *StdWithCache[T]) Pluck(column string, dest interface{}) *gorm.DB

Pluck queries a single column from a model, returning in the slice dest. E.g.: var ages []int64 db.Model(&users).Pluck("age", &ages)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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