mongodb

package
v0.0.0-...-c4d4255 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStruct     = errors.New("not a struct")
	ErrNilCollection = errors.New("nil collection")
	ErrNilSerializer = errors.New("nil serializer")
)

Functions

func NewRepositoryOptions

func NewRepositoryOptions(fnopts ...RepositoryOptions) *repositoryOptions

func NewSearchOptions

func NewSearchOptions(fnopts ...SearchOptions) *searchOptions

Types

type Method

type Method string
const (
	CURSOR  Method = "cursor"
	DEFAULT Method = "default"
)

func NewMethod

func NewMethod(method string) Method

type Repository

type Repository[M any] interface {
	FindOne(ctx context.Context, id string) (M, error)
	Find(ctx context.Context, ids []string) ([]M, error)
	FindAll(ctx context.Context) ([]M, error)
	Search(ctx context.Context, filters map[string][]any, opts ...SearchOptions) ([]M, error)

	CountDocuments(ctx context.Context, filters map[string][]any) (int64, error)

	Upsert(ctx context.Context, id string, m M) error

	Delete(ctx context.Context, id string) (M, error)
	DeleteMany(ctx context.Context, filters map[string][]any) error
}

func NewRepository

func NewRepository[M, D any](col *mongo.Collection, ser Serializer[M, D]) (Repository[M], error)

func NewSimpleRepository

func NewSimpleRepository[M any](col *mongo.Collection, opts ...RepositoryOptions) (Repository[M], error)

type RepositoryOptions

type RepositoryOptions func(*repositoryOptions)

func WithBloomFilter

func WithBloomFilter(bf filters.Bloom[string]) RepositoryOptions

func WithDefaultPageSize

func WithDefaultPageSize(size int) RepositoryOptions

func WithMaxPageSize

func WithMaxPageSize(size int) RepositoryOptions

type SearchOptions

type SearchOptions func(*searchOptions)

func WithPage

func WithPage(page int) SearchOptions

func WithPageMethod

func WithPageMethod(method string) SearchOptions

func WithPageSize

func WithPageSize(pageSize int) SearchOptions

func WithSort

func WithSort(sort map[string]int) SearchOptions

type Serializer

type Serializer[M, D any] interface {
	Serialize(m M) (D, error)
	Deserialize(d D) (M, error)
}

Jump to

Keyboard shortcuts

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