keelmongo

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseCursor

func CloseCursor(cursor *mongo.Cursor)

CloseCursor with defer

func Readme added in v0.17.0

func Readme() string

Types

type Collection

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

Collection can only be used in the Persistor.WithCollection call.ss

func NewCollection

func NewCollection(db *mongo.Database, name string, opts ...CollectionOption) (*Collection, error)

func (*Collection) Aggregate

func (c *Collection) Aggregate(ctx context.Context, pipeline mongo.Pipeline, results interface{}, opts ...*options.AggregateOptions) error

func (*Collection) AggregateIterate

func (c *Collection) AggregateIterate(ctx context.Context, pipeline mongo.Pipeline, handler IterateHandlerFn, opts ...*options.AggregateOptions) error

func (*Collection) Col

func (c *Collection) Col() *mongo.Collection

func (*Collection) Count

func (c *Collection) Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)

Count returns the count of documents

func (*Collection) CountAll

func (c *Collection) CountAll(ctx context.Context) (int64, error)

CountAll returns the count of all documents

func (*Collection) DB added in v0.9.10

func (c *Collection) DB() *mongo.Database

func (*Collection) Delete

func (c *Collection) Delete(ctx context.Context, id string) error

func (*Collection) Exists

func (c *Collection) Exists(ctx context.Context, id string) (bool, error)

func (*Collection) Find

func (c *Collection) Find(ctx context.Context, filter, results interface{}, opts ...*options.FindOptions) error

func (*Collection) FindIterate

func (c *Collection) FindIterate(ctx context.Context, filter interface{}, handler IterateHandlerFn, opts ...*options.FindOptions) error

func (*Collection) FindOne

func (c *Collection) FindOne(ctx context.Context, filter, result interface{}, opts ...*options.FindOneOptions) error

func (*Collection) Get

func (c *Collection) Get(ctx context.Context, id string, result interface{}, opts ...*options.FindOneOptions) error

func (*Collection) Insert added in v0.5.0

func (c *Collection) Insert(ctx context.Context, entity Entity) error

func (*Collection) InsertMany added in v0.13.0

func (c *Collection) InsertMany(ctx context.Context, entities []Entity) error

func (*Collection) Upsert

func (c *Collection) Upsert(ctx context.Context, id string, entity Entity) error

func (*Collection) UpsertMany added in v0.13.0

func (c *Collection) UpsertMany(ctx context.Context, entities []Entity) error

UpsertMany - NOTE: upsert many does NOT through an explicit error on dirty write so we can only assume it.

type CollectionOption

type CollectionOption func(*CollectionOptions)

Collection can only be used in the Persistor.WithCollection call.ss

func CollectionWithIndexes

func CollectionWithIndexes(v ...mongo.IndexModel) CollectionOption

func CollectionWithIndexesCommitQuorumString

func CollectionWithIndexesCommitQuorumString(v string) CollectionOption

func CollectionWithIndexesCommitQuorumVotingMembers

func CollectionWithIndexesCommitQuorumVotingMembers(v context.Context) CollectionOption

func CollectionWithIndexesContext

func CollectionWithIndexesContext(v int32) CollectionOption

func CollectionWithIndexesMaxTime

func CollectionWithIndexesMaxTime(v time.Duration) CollectionOption

func CollectionWithIndexesQuorumMajority

func CollectionWithIndexesQuorumMajority() CollectionOption

func CollectionWithReadConcern

func CollectionWithReadConcern(v *readconcern.ReadConcern) CollectionOption

func CollectionWithReadPreference

func CollectionWithReadPreference(v *readpref.ReadPref) CollectionOption

func CollectionWithRegistry

func CollectionWithRegistry(v *bsoncodec.Registry) CollectionOption

func CollectionWithWriteConcern

func CollectionWithWriteConcern(v *writeconcern.WriteConcern) CollectionOption

type CollectionOptions

type CollectionOptions struct {
	*options.CollectionOptions
	*options.CreateIndexesOptions
	Indexes        []mongo.IndexModel
	IndexesContext context.Context
}

Collection can only be used in the Persistor.WithCollection call.ss

func DefaultCollectionOptions

func DefaultCollectionOptions() CollectionOptions

type DecodeFn

type DecodeFn func(val interface{}) error

type Entity

type Entity interface {
	SetID(string)
	GetID() string
}

type EntityWithTimestamps

type EntityWithTimestamps interface {
	SetCreatedAt(time.Time)
	GetCreatedAt() time.Time
	SetUpdatedAt(time.Time)
	GetUpdatedAt() time.Time
}

type EntityWithVersion

type EntityWithVersion interface {
	GetVersion() uint32
	IncreaseVersion() uint32
}

type IterateHandlerFn

type IterateHandlerFn func(decode DecodeFn) error

type Option

type Option func(o *Options)

Persistor exported to used also for embedding into other types in foreign packages.

func WithClientOptions

func WithClientOptions(v *options.ClientOptions) Option

func WithDatabaseOptions

func WithDatabaseOptions(v *options.DatabaseOptions) Option

func WithOtelEnabled

func WithOtelEnabled(v bool) Option

func WithOtelOptions

func WithOtelOptions(v ...otelmongo.Option) Option

type Options

type Options struct {
	OtelEnabled     bool
	OtelOptions     []otelmongo.Option
	ClientOptions   *options.ClientOptions
	DatabaseOptions *options.DatabaseOptions
}

Persistor exported to used also for embedding into other types in foreign packages.

func DefaultOptions

func DefaultOptions() Options

type Persistor

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

Persistor exported to used also for embedding into other types in foreign packages.

func New

func New(ctx context.Context, uri string, opts ...Option) (*Persistor, error)

New ...

func (Persistor) Client added in v0.9.10

func (p Persistor) Client() *mongo.Client

func (Persistor) Close

func (p Persistor) Close(ctx context.Context) error

func (Persistor) Collection

func (p Persistor) Collection(name string, opts ...CollectionOption) (*Collection, error)

func (Persistor) DB added in v0.9.10

func (p Persistor) DB() *mongo.Database

func (Persistor) HasCollection

func (p Persistor) HasCollection(ctx context.Context, name string) (bool, error)

HasCollection checks if the given collection exists

func (Persistor) Ping

func (p Persistor) Ping(ctx context.Context) error

Jump to

Keyboard shortcuts

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