mongox

package
v0.0.0-...-5cbc45b Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewClientCollection = NewCollection

Functions

func And

func And(filter interface{}, key string, f interface{}) interface{}

func AppendE

func AppendE(f interface{}, elements ...bson.E) interface{}

func AppendI

func AppendI(f interface{}, elements ...interface{}) interface{}

func DToM

func DToM(i interface{}) interface{}

func GetE

func GetE(f interface{}, k string) interface{}

func IsTransactionAvailable

func IsTransactionAvailable(original string) bool

func IsTransactionError

func IsTransactionError(err error) bool

Types

type BatchConsumer

type BatchConsumer struct {
	Size     int
	Rows     []bson.Raw
	Callback func([]bson.Raw) error
}

func (*BatchConsumer) Consume

func (c *BatchConsumer) Consume(raw bson.Raw) error

type Client

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

func NewClient

func NewClient(database string, c *mongo.Client) *Client

func NewClientWithDatabase

func NewClientWithDatabase(db *mongo.Database) *Client

func (*Client) Collection

func (c *Client) Collection(col string) *Collection

func (*Client) Database

func (c *Client) Database() *mongo.Database

func (*Client) Transaction

func (c *Client) Transaction() usecasex.Transaction

func (*Client) WithCollection

func (c *Client) WithCollection(col string) *Collection

WithCollection is deprecated

func (*Client) WithTransaction

func (c *Client) WithTransaction() *Client

type ClientCollection

type ClientCollection = Collection

type Collection

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

func NewCollection

func NewCollection(c *mongo.Collection) *Collection

func (*Collection) Aggregate

func (c *Collection) Aggregate(ctx context.Context, pipeline []any, consumer Consumer, options ...*options.AggregateOptions) error

func (*Collection) AggregateOne

func (c *Collection) AggregateOne(ctx context.Context, pipeline []any, consumer Consumer, options ...*options.AggregateOptions) error

func (*Collection) Client

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

func (*Collection) Count

func (c *Collection) Count(ctx context.Context, filter any) (int64, error)

func (*Collection) CountAggregation

func (c *Collection) CountAggregation(ctx context.Context, pipeline []any) (int64, error)

func (*Collection) CreateOne

func (c *Collection) CreateOne(ctx context.Context, id string, doc any) error

func (*Collection) Find

func (c *Collection) Find(ctx context.Context, filter any, consumer Consumer, options ...*options.FindOptions) error

func (*Collection) FindOne

func (c *Collection) FindOne(ctx context.Context, filter any, consumer Consumer, options ...*options.FindOneOptions) error

func (*Collection) Indexes

func (c *Collection) Indexes(ctx context.Context, keys, uniqueKeys []string) ([]string, []string, error)

Indexes creates and deletes indexes by keys declaratively

func (*Collection) Indexes2

func (c *Collection) Indexes2(ctx context.Context, inputs ...Index) (IndexResult, error)

Indexes creates and deletes indexes declaratively

func (*Collection) Paginate

func (c *Collection) Paginate(ctx context.Context, rawFilter any, s *usecasex.Sort, p *usecasex.Pagination, consumer Consumer, opts ...*options.FindOptions) (*usecasex.PageInfo, error)

func (*Collection) PaginateAggregation

func (c *Collection) PaginateAggregation(ctx context.Context, pipeline []any, s *usecasex.Sort, p *usecasex.Pagination, consumer Consumer, opts ...*options.AggregateOptions) (*usecasex.PageInfo, error)

func (*Collection) RemoveAll

func (c *Collection) RemoveAll(ctx context.Context, f any) error

func (*Collection) RemoveOne

func (c *Collection) RemoveOne(ctx context.Context, f any) error

func (*Collection) SaveAll

func (c *Collection) SaveAll(ctx context.Context, ids []string, updates []any) error

func (*Collection) SaveOne

func (c *Collection) SaveOne(ctx context.Context, id string, replacement any) error

func (*Collection) SetOne

func (c *Collection) SetOne(ctx context.Context, id string, replacement any) error

func (*Collection) UpdateMany

func (c *Collection) UpdateMany(ctx context.Context, filter, update any) error

func (*Collection) UpdateManyMany

func (c *Collection) UpdateManyMany(ctx context.Context, updates []Update) error

type Consumer

type Consumer interface {
	Consume(raw bson.Raw) error
}

type FuncConsumer

type FuncConsumer func(raw bson.Raw) error

func (FuncConsumer) Consume

func (c FuncConsumer) Consume(raw bson.Raw) error

type Index

type Index struct {
	Name               string
	Key                bson.D
	Unique             bool
	ExpireAfterSeconds *int32
	Filter             bson.M `bson:"partialFilterExpression"`
}

func IndexFromKey

func IndexFromKey(key string, unique bool) Index

func IndexFromKeys

func IndexFromKeys(keys []string, unique bool) []Index

func TTLIndexFromKey

func TTLIndexFromKey(key string, expireAfterSeconds int32) Index

func (Index) Equal

func (i Index) Equal(j Index) bool

func (Index) Model

func (i Index) Model() mongo.IndexModel

func (Index) Normalize

func (i Index) Normalize() Index

type IndexList

type IndexList []Index

func (IndexList) AddNamePrefix

func (l IndexList) AddNamePrefix() IndexList

func (IndexList) Models

func (l IndexList) Models() []mongo.IndexModel

func (IndexList) Names

func (l IndexList) Names() []string

func (IndexList) NamesWithoutPrefix

func (l IndexList) NamesWithoutPrefix() []string

func (IndexList) Normalize

func (l IndexList) Normalize() []Index

func (IndexList) RemoveDefaultIndex

func (l IndexList) RemoveDefaultIndex() IndexList

type IndexResult

type IndexResult util.DiffResult[Index]

func (IndexResult) AddedNames

func (i IndexResult) AddedNames() []string

func (IndexResult) DeletedNames

func (i IndexResult) DeletedNames() []string

func (IndexResult) UpdatedNames

func (i IndexResult) UpdatedNames() []string

type SimpleConsumer

type SimpleConsumer[T any] func(data T) error

func (SimpleConsumer[T]) Consume

func (s SimpleConsumer[T]) Consume(raw bson.Raw) error

type SliceConsumer

type SliceConsumer[T any] struct {
	Result []T
	// contains filtered or unexported fields
}

func (*SliceConsumer[T]) Consume

func (s *SliceConsumer[T]) Consume(raw bson.Raw) error

type SliceFuncConsumer

type SliceFuncConsumer[T, K any] struct {
	Result []K
	// contains filtered or unexported fields
}

func NewSliceFuncConsumer

func NewSliceFuncConsumer[T, K any](f func(t T) (K, error)) *SliceFuncConsumer[T, K]

func (*SliceFuncConsumer[T, K]) Consume

func (s *SliceFuncConsumer[T, K]) Consume(raw bson.Raw) error

type SliceRawFuncConsumer

type SliceRawFuncConsumer[T any] struct {
	Result []T
	// contains filtered or unexported fields
}

func NewSliceRawFuncConsumer

func NewSliceRawFuncConsumer[T any](f func(t bson.Raw) (T, error)) *SliceRawFuncConsumer[T]

func (*SliceRawFuncConsumer[T]) Consume

func (s *SliceRawFuncConsumer[T]) Consume(raw bson.Raw) error

type Transaction

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

func NewTransaction

func NewTransaction(client *mongo.Client) *Transaction

func (*Transaction) Begin

func (t *Transaction) Begin(ctx context.Context) (usecasex.Tx, error)

type Tx

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

Tx implements usecasex.Tx, but note that it's not goroutine-safe.

func (*Tx) Commit

func (t *Tx) Commit()

func (*Tx) Context

func (t *Tx) Context() context.Context

func (*Tx) End

func (t *Tx) End(ctx context.Context) error

func (*Tx) IsCommitted

func (t *Tx) IsCommitted() bool

type Update

type Update struct {
	Filter       any
	Update       any
	ArrayFilters []any
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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