database

package
v1.1.894 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DirectionBackward = 1
View Source
const DirectionForward = -1

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")

Functions

This section is empty.

Types

type AggrListPage added in v1.1.882

type AggrListPage[T any] struct {
	L    []T   `json:"l"`
	Page *Page `json:"page"`
}

func FindWithPage added in v1.1.881

func FindWithPage[T any](
	ctx context.Context,
	repo *Repository,
	filter bson.M,
	sortField string,
	ptI interface{},
	optChain ...*options.FindOptions,
) (*AggrListPage[T], error)

type MongoDB

type MongoDB struct {
	// contains filtered or unexported fields
}

func GetMongoDB deprecated

func GetMongoDB(opt *options.ClientOptions, database string) *MongoDB

Deprecated: GetMongoDB 方法已废弃,请使用 NewMongoDB 直接创建实例。

func NewMongoDB

func NewMongoDB(opt *options.ClientOptions, database string) *MongoDB

func (*MongoDB) CheckCollectionExist added in v0.4.2

func (m *MongoDB) CheckCollectionExist(CollectionName string)

func (*MongoDB) Disconnect

func (m *MongoDB) Disconnect()

func (*MongoDB) GetClient

func (m *MongoDB) GetClient() *mongo.Client

func (*MongoDB) GetCollection

func (m *MongoDB) GetCollection(collectionName string) *mongo.Collection

func (*MongoDB) GetDatabase

func (m *MongoDB) GetDatabase() *mongo.Database

func (*MongoDB) Ping

func (m *MongoDB) Ping(ctx context.Context)

type Page added in v1.1.881

type Page struct {
	Count       int64  `json:"count"`
	IsLastPage  bool   `json:"isLastPage"`
	PageTag     string `json:"pageTag"`
	PrevPageTag string `json:"prevPageTag"`
}

func (*Page) Direction added in v1.1.881

func (p *Page) Direction() (int, string)

type RCO

type Repo added in v1.1.890

type Repo = Repository

func GetRepo added in v1.1.890

func GetRepo(db *MongoDB, collection string) *Repo

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func GetRepository

func GetRepository(db *MongoDB, collection string) *Repository

func (*Repository) Collection added in v0.3.0

func (r *Repository) Collection() *mongo.Collection

func (*Repository) DeleteMany

func (r *Repository) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Repository) DeleteOne

func (r *Repository) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Repository) Find

func (r *Repository) Find(ctx context.Context, entityList interface{}, filter interface{}, opts ...*options.FindOptions) error

func (*Repository) FindOne

func (r *Repository) FindOne(ctx context.Context, entity interface{}, filter interface{}, opts ...*options.FindOneOptions) error

func (*Repository) FindOneAndUpdate

func (r *Repository) FindOneAndUpdate(ctx context.Context, entity interface{}, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) error

func (*Repository) InsertOne

func (r *Repository) InsertOne(ctx context.Context, doc interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

func (*Repository) UpdateMany

func (r *Repository) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*Repository) UpdateOne

func (r *Repository) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type RepositoryCache

type RepositoryCache struct {
	*Repository
	// contains filtered or unexported fields
}

func GetRepositoryCache

func GetRepositoryCache(repo *Repository, cache redis.UniversalClient, opt *RepositoryCacheOption) *RepositoryCache

func (*RepositoryCache) DelCache

func (r *RepositoryCache) DelCache(ctx context.Context, key string)

func (*RepositoryCache) DelCacheByFilter

func (r *RepositoryCache) DelCacheByFilter(ctx context.Context, filter interface{})

func (*RepositoryCache) DeleteMany

func (r *RepositoryCache) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*RepositoryCache) DeleteOne

func (r *RepositoryCache) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*RepositoryCache) Find

func (r *RepositoryCache) Find(ctx context.Context, entityList interface{}, filter interface{}, opts ...*options.FindOptions) error

func (*RepositoryCache) FindOne

func (r *RepositoryCache) FindOne(ctx context.Context, entity interface{}, filter interface{}, opts ...*RepositoryCacheOption) error

func (*RepositoryCache) FindOneAndUpdate

func (r *RepositoryCache) FindOneAndUpdate(ctx context.Context, entity interface{}, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) error

func (*RepositoryCache) GenCacheK

func (r *RepositoryCache) GenCacheK(filter interface{}) (string, error)

func (*RepositoryCache) InsertOne

func (r *RepositoryCache) InsertOne(ctx context.Context, doc interface{}, filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

func (*RepositoryCache) UpdateMany

func (r *RepositoryCache) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*RepositoryCache) UpdateOne

func (r *RepositoryCache) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type RepositoryCacheOption

type RepositoryCacheOption struct {
	Prefix string
	TTL    int
	Debug  bool
}

Jump to

Keyboard shortcuts

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