Documentation
¶
Overview ¶
Package clientinfra provides shared Mongo client setup helpers.
Index ¶
- func EnsureIndexes(timeout time.Duration, ensure func(context.Context) error) error
- func Ping(ctx context.Context, client *mongodriver.Client, normalizeNil bool) error
- func ResolveCollectionName(collection string, defaultCollection string) string
- func ResolveTimeout(timeout time.Duration, defaultTimeout time.Duration) time.Duration
- func ValidateCollections(message string, collections ...any) error
- func ValidateMongoOptions(client *mongodriver.Client, database string) error
- func WithTimeout(ctx context.Context, timeout time.Duration, normalizeNil bool) (context.Context, context.CancelFunc)
- type Collection
- func (c Collection) Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (CursorReader, error)
- func (c Collection) FindOne(ctx context.Context, filter any, ...) SingleResultDecoder
- func (c Collection) Indexes() IndexCreator
- func (c Collection) InsertOne(ctx context.Context, document any, ...) (*mongodriver.InsertOneResult, error)
- func (c Collection) UpdateOne(ctx context.Context, filter any, update any, ...) (*mongodriver.UpdateResult, error)
- type Cursor
- type CursorReader
- type FindCollection
- type FindOneCollection
- type IndexCreator
- type IndexView
- type IndexedCollection
- type InsertOneCollection
- type SingleResult
- type SingleResultDecoder
- type UpdateOneCollection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureIndexes ¶
EnsureIndexes runs index initialization with a timeout-bounded background context.
func ResolveCollectionName ¶ added in v1.1.3
ResolveCollectionName applies the package default when the configured collection is empty.
func ResolveTimeout ¶
ResolveTimeout applies the package default when the configured timeout is not positive.
func ValidateCollections ¶ added in v1.1.3
ValidateCollections checks that test or production collection adapters are present.
func ValidateMongoOptions ¶
func ValidateMongoOptions(client *mongodriver.Client, database string) error
ValidateMongoOptions checks the shared required Mongo constructor inputs.
Types ¶
type Collection ¶ added in v1.1.3
type Collection struct {
Coll *mongodriver.Collection
}
Collection adapts mongodriver.Collection to feature-local collection interfaces.
func NewCollection ¶ added in v1.1.3
func NewCollection(client *mongodriver.Client, database string, collection string) Collection
NewCollection returns the common adapter for a concrete Mongo collection.
func (Collection) Find ¶ added in v1.1.3
func (c Collection) Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (CursorReader, error)
Find forwards to the wrapped Collection.
func (Collection) FindOne ¶ added in v1.1.3
func (c Collection) FindOne(ctx context.Context, filter any, opts ...options.Lister[options.FindOneOptions]) SingleResultDecoder
FindOne forwards to the wrapped Collection.
func (Collection) Indexes ¶ added in v1.1.3
func (c Collection) Indexes() IndexCreator
Indexes forwards to the wrapped Collection.
func (Collection) InsertOne ¶ added in v1.1.3
func (c Collection) InsertOne(ctx context.Context, document any, opts ...options.Lister[options.InsertOneOptions]) (*mongodriver.InsertOneResult, error)
InsertOne forwards to the wrapped Collection.
func (Collection) UpdateOne ¶ added in v1.1.3
func (c Collection) UpdateOne(ctx context.Context, filter any, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongodriver.UpdateResult, error)
UpdateOne forwards to the wrapped Collection.
type Cursor ¶ added in v1.1.0
type Cursor struct {
Cur *mongodriver.Cursor
}
Cursor adapts mongodriver.Cursor to a feature-local interface.
type CursorReader ¶ added in v1.1.3
type CursorReader interface {
Next(ctx context.Context) bool
Decode(val any) error
Err() error
Close(ctx context.Context) error
}
CursorReader is the common cursor shape used by feature clients.
type FindCollection ¶ added in v1.1.3
type FindCollection interface {
Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (CursorReader, error)
}
FindCollection captures the common Mongo Find operation.
type FindOneCollection ¶ added in v1.1.3
type FindOneCollection interface {
FindOne(ctx context.Context, filter any, opts ...options.Lister[options.FindOneOptions]) SingleResultDecoder
}
FindOneCollection captures the common Mongo FindOne operation.
type IndexCreator ¶ added in v1.1.3
type IndexCreator interface {
CreateOne(ctx context.Context, model mongodriver.IndexModel, opts ...options.Lister[options.CreateIndexesOptions]) (string, error)
}
IndexCreator is the common index creation shape used by feature clients.
type IndexView ¶ added in v1.1.0
type IndexView struct {
View mongodriver.IndexView
}
IndexView adapts mongodriver.IndexView to a feature-local interface.
func (IndexView) CreateOne ¶ added in v1.1.0
func (v IndexView) CreateOne(ctx context.Context, model mongodriver.IndexModel, opts ...options.Lister[options.CreateIndexesOptions]) (string, error)
CreateOne forwards to the wrapped IndexView.
type IndexedCollection ¶ added in v1.1.3
type IndexedCollection interface {
Indexes() IndexCreator
}
IndexedCollection captures access to Mongo index management.
type InsertOneCollection ¶ added in v1.1.3
type InsertOneCollection interface {
InsertOne(ctx context.Context, document any, opts ...options.Lister[options.InsertOneOptions]) (*mongodriver.InsertOneResult, error)
}
InsertOneCollection captures the common Mongo InsertOne operation.
type SingleResult ¶ added in v1.1.0
type SingleResult struct {
Res *mongodriver.SingleResult
}
SingleResult adapts mongodriver.SingleResult to a feature-local interface.
func (SingleResult) Decode ¶ added in v1.1.0
func (r SingleResult) Decode(val any) error
Decode forwards to the wrapped SingleResult.
type SingleResultDecoder ¶ added in v1.1.3
SingleResultDecoder is the common decode-only shape of Mongo single-result reads.
type UpdateOneCollection ¶ added in v1.1.3
type UpdateOneCollection interface {
UpdateOne(ctx context.Context, filter any, update any, opts ...options.Lister[options.UpdateOneOptions]) (*mongodriver.UpdateResult, error)
}
UpdateOneCollection captures the common Mongo UpdateOne operation.