template-monorepo/internal/library/mongo/usecase.go

36 lines
1.8 KiB
Go
Raw Normal View History

2026-05-19 13:33:04 +00:00
package mongo
import (
"context"
"github.com/zeromicro/go-zero/core/stores/mon"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
type DocumentDBUseCase interface {
PopulateIndex(ctx context.Context, key string, sort int32, unique bool) error
PopulateTTLIndex(ctx context.Context, key string, sort int32, unique bool, ttl int32) error
PopulateMultiIndex(ctx context.Context, keys []string, sorts []int32, unique bool) error
GetClient() *mon.Model
}
type DocumentDBWithCacheUseCase interface {
DocumentDBUseCase
CacheUseCase
DeleteOne(ctx context.Context, key string, filter any, opts ...options.Lister[options.DeleteOneOptions]) (int64, error)
FindOne(ctx context.Context, key string, v, filter any, opts ...options.Lister[options.FindOneOptions]) error
FindOneAndDelete(ctx context.Context, key string, v, filter any, opts ...options.Lister[options.FindOneAndDeleteOptions]) error
FindOneAndReplace(ctx context.Context, key string, v, filter, replacement any, opts ...options.Lister[options.FindOneAndReplaceOptions]) error
InsertOne(ctx context.Context, key string, document any, opts ...options.Lister[options.InsertOneOptions]) (*mongo.InsertOneResult, error)
UpdateByID(ctx context.Context, key string, id, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongo.UpdateResult, error)
UpdateMany(ctx context.Context, keys []string, filter, update any, opts ...options.Lister[options.UpdateManyOptions]) (*mongo.UpdateResult, error)
UpdateOne(ctx context.Context, key string, filter, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongo.UpdateResult, error)
}
type CacheUseCase interface {
DelCache(ctx context.Context, keys ...string) error
GetCache(ctx context.Context, key string, v any) error
SetCache(ctx context.Context, key string, v any) error
}