persistence

package
v0.0.0-...-9edfad7 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModelInterface

type BaseModelInterface interface {
	GetID() string
	SetID(id primitive.ObjectID)
	GetCreatedAt() *timestamppb.Timestamp
	SetCreatedAt(t *timestamppb.Timestamp)
	GetUpdatedAt() *timestamppb.Timestamp
	SetUpdatedAt(t *timestamppb.Timestamp)
}

BaseModelInterface ensures that the type has an embedded BaseModel or equivalent fields.

type IRepository

type IRepository[T BaseModelInterface] interface {
	Create(c context.Context, item T) error
	GetByID(c context.Context, id string) (item T, err error)
	List(c context.Context, cond Pagination) (items []T, total int, err error)
	Update(c context.Context, item T) error
	Delete(c context.Context, id string) error
}

IRepository is a generic interface for repositories.

func NewMongoRepository

func NewMongoRepository[T BaseModelInterface](coll *mongo.Collection) IRepository[T]

NewMongoRepository is to create a new mongo repository.

type Pagination

type Pagination struct {
	Limit  int64
	Offset int64
}

Pagination is a struct for pagination.

Jump to

Keyboard shortcuts

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