repoutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: LGPL-2.1 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

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

Repo represents the client for common usages

func NewRepo

func NewRepo[T any](db *gorm.DB) *Repo[T]

NewRepo creates new Repo instance

func (*Repo[T]) Count

func (d *Repo[T]) Count(ctx context.Context, count *int64, conds ...any) error

Count counts records that match given conditions

func (*Repo[T]) Create

func (d *Repo[T]) Create(ctx context.Context, input *T) error

Create creates a new record

func (*Repo[T]) CreateInBatches

func (d *Repo[T]) CreateInBatches(ctx context.Context, input []T, batchSize int) error

CreateInBatches creates multiple records in batches

func (*Repo[T]) Delete

func (d *Repo[T]) Delete(ctx context.Context, conds ...any) error

Delete deletes a record by conditions

func (*Repo[T]) Existed

func (d *Repo[T]) Existed(ctx context.Context, conds ...any) (bool, error)

Existed checks if a record exists by conditions

func (*Repo[T]) List

func (d *Repo[T]) List(ctx context.Context, output interface{}, conds ...any) error

List gets all records that match given conditions

func (*Repo[T]) Read

func (d *Repo[T]) Read(ctx context.Context, output *T, conds ...any) error

Read get a record by conds

func (*Repo[T]) ReadAllByCondition

func (d *Repo[T]) ReadAllByCondition(ctx context.Context, output interface{}, count *int64, lqc *requestutil.ListQueryCondition) error

ReadAllByCondition retrieves a list of entities based on the provided query conditions.

func (*Repo[T]) ReadByID

func (d *Repo[T]) ReadByID(ctx context.Context, output *T, id string) error

ReadByID gets a record by primary key

func (*Repo[T]) ReadByUpdate

func (d *Repo[T]) ReadByUpdate(ctx context.Context, options string, output *T, conds ...any) error

ReadByUpdate gets a record and lock it for update

func (*Repo[T]) Update

func (d *Repo[T]) Update(ctx context.Context, updates any, conds ...any) error

Update updates a record by conditions

Jump to

Keyboard shortcuts

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