Documentation
¶
Index ¶
- Variables
- func BuildBulkOperation(filter interface{}, update interface{}, data interface{}) *mongo.UpdateOneModel
- func CodecRegistry(options *Options) *bsoncodec.RegistryBuilder
- func GetLogLevel(data interface{}) int
- type Client
- type ClientAPI
- type ClientCollection
- type ClientCursor
- type ClientDatabase
- type ClientIndex
- type ClientSingleResult
- type CollectionAPI
- type CursorAPI
- type IndexAPI
- type MockClient
- func (p *MockClient) Connect(ctx context.Context) error
- func (p *MockClient) GetCollection() CollectionAPI
- func (p *MockClient) Ping(ctx context.Context, rp *readpref.ReadPref) error
- func (p *MockClient) SetCollection(collection string)
- func (p *MockClient) SetCursor(*mongo.Cursor) CursorAPI
- func (p *MockClient) SetSingleResult(*mongo.SingleResult) SingleResultAPI
- type MockCollection
- func (c *MockCollection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
- func (c *MockCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, ...) (*mongo.BulkWriteResult, error)
- func (c *MockCollection) CountDocuments(context.Context, interface{}, ...*mgoOtions.CountOptions) (int64, error)
- func (c *MockCollection) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (c *MockCollection) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (c *MockCollection) Find(ctx context.Context, filter interface{}, opts ...*mgoOtions.FindOptions) (*mongo.Cursor, error)
- func (c *MockCollection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, ...) *mongo.SingleResult
- func (c *MockCollection) GetIndex() IndexAPI
- func (c *MockCollection) InsertOne(ctx context.Context, document interface{}, opts ...*mgoOtions.InsertOneOptions) (*mongo.InsertOneResult, error)
- func (c *MockCollection) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, ...) (*mongo.UpdateResult, error)
- func (c *MockCollection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, ...) (*mongo.UpdateResult, error)
- type MockCursor
- type MockIndex
- func (i *MockIndex) CreateMany(_ context.Context, _ []mongo.IndexModel, _ ...*options.CreateIndexesOptions) ([]string, error)
- func (i *MockIndex) CreateOne(_ context.Context, _ mongo.IndexModel, _ ...*options.CreateIndexesOptions) (string, error)
- func (i *MockIndex) DropOne(_ context.Context, _ string, _ ...*options.DropIndexesOptions) (bson.Raw, error)
- func (i *MockIndex) ListSpecifications(_ context.Context, _ ...*options.ListIndexesOptions) ([]*mongo.IndexSpecification, error)
- type MockSingleResult
- type MockbsonReader
- type MockbsonWriter
- type Mongo
- type MongoAPI
- type MongoDB
- func (m *MongoDB) Aggregate(pipeline mongo.Pipeline, data interface{}) error
- func (m *MongoDB) Connect() error
- func (m *MongoDB) CountDocuments(filter interface{}, count *int64, countOptions ...*options.CountOptions) (err error)
- func (m *MongoDB) CreateIndexes(opt mongo.IndexModel) error
- func (m *MongoDB) CreateManyIndexes(opt []mongo.IndexModel) error
- func (m *MongoDB) Delete(filter interface{}) error
- func (m *MongoDB) DeleteAll() error
- func (m *MongoDB) DropIndex(index string) error
- func (m *MongoDB) FindAndUpdate(filter interface{}, update interface{}, data interface{}) error
- func (m *MongoDB) Get(filter interface{}, data interface{}, findOptions ...*options.FindOptions) error
- func (m *MongoDB) Incr(key string) (int64, error)
- func (m *MongoDB) Insert(value interface{}) error
- func (m *MongoDB) InsertBulk(operations []*mongo.UpdateOneModel) error
- func (m *MongoDB) ListIndexes() ([]string, error)
- func (m *MongoDB) SetCollection(collection string) MongoAPI
- func (m *MongoDB) SetOptions(opts ...Option) MongoAPI
- func (m *MongoDB) Update(filter interface{}, update interface{}) error
- func (m *MongoDB) Upsert(filter interface{}, update interface{}) error
- type Option
- type Options
- type SingleResultAPI
Constants ¶
This section is empty.
Variables ¶
var ProtoCodecFunc = func(_ bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { if !val.IsValid() || val.Type() != tsProtoType { return bsoncodec.ValueEncoderError{Name: "ObjectIDEncodeValue", Types: []reflect.Type{tsProtoType}, Received: val} } s := val.Interface().(*timestamppb.Timestamp) return vw.WriteDateTime(s.Seconds * 1000) }
ProtoCodecFunc is the Proto Encoding Function
var ProtoDeCodecFunc = func(_ bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { read, err := vr.ReadDateTime() if err != nil { return err } val.Interface().(*timestamppb.Timestamp).Seconds = read / 1000 return nil }
ProtoDeCodecFunc is the Proto Dencoding Function
var StrCodecFunc = func(_ bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { if !val.IsValid() || val.Type() != tsStrType { return bsoncodec.ValueEncoderError{Name: "ObjectIDEncodeValue", Types: []reflect.Type{tsProtoType}, Received: val} } s := val.Interface().(string) t, err := time.Parse(time.RFC3339Nano, s) if err != nil { return vw.WriteString(s) } return vw.WriteDateTime(t.Unix() * 1000) }
StrCodecFunc is the String Encoding Function
Functions ¶
func BuildBulkOperation ¶
func BuildBulkOperation(filter interface{}, update interface{}, data interface{}) *mongo.UpdateOneModel
BuildBulkOperation create a single bulk operation
func CodecRegistry ¶ added in v0.13.3
func CodecRegistry(options *Options) *bsoncodec.RegistryBuilder
CodecRegistry create a new bsoncode
func GetLogLevel ¶ added in v0.10.1
func GetLogLevel(data interface{}) int
GetLogLevel returns log level from data value
Types ¶
type Client ¶
Client is the internal Mongo Client
func (*Client) GetCollection ¶
func (c *Client) GetCollection() CollectionAPI
GetCollection return a CollectionAPI
func (*Client) SetCollection ¶
SetCollection set collection name for the internal client
func (*Client) SetSingleResult ¶
func (c *Client) SetSingleResult(singleresult *mongo.SingleResult) SingleResultAPI
SetSingleResult return a SingleResultAPI
type ClientAPI ¶
type ClientAPI interface { SetCollection(collection string) GetCollection() CollectionAPI SetCursor(*mongo.Cursor) CursorAPI SetSingleResult(*mongo.SingleResult) SingleResultAPI Connect(context.Context) error Ping(context.Context, *readpref.ReadPref) error }
ClientAPI is the internal Client API interface
type ClientCollection ¶
type ClientCollection struct {
*mgo.Collection
}
ClientCollection is the internal Mongo Collection
func (*ClientCollection) GetIndex ¶
func (c *ClientCollection) GetIndex() IndexAPI
GetIndex return an IndexAPI from collection indexes
type ClientCursor ¶
ClientCursor is the internal Mongo Cursor
type ClientDatabase ¶
ClientDatabase is the internal Mongo Database
type ClientIndex ¶
ClientIndex is the internal Client Index
type ClientSingleResult ¶
type ClientSingleResult struct {
*mgo.SingleResult
}
ClientSingleResult is the internal Single Result
type CollectionAPI ¶
type CollectionAPI interface { GetIndex() IndexAPI InsertOne(context.Context, interface{}, ...*mgoOtions.InsertOneOptions) (*mongo.InsertOneResult, error) BulkWrite(context.Context, []mongo.WriteModel, ...*mgoOtions.BulkWriteOptions) (*mongo.BulkWriteResult, error) Find(context.Context, interface{}, ...*options.FindOptions) (*mongo.Cursor, error) DeleteOne(context.Context, interface{}, ...*options.DeleteOptions) (*mongo.DeleteResult, error) DeleteMany(context.Context, interface{}, ...*options.DeleteOptions) (*mongo.DeleteResult, error) UpdateOne(context.Context, interface{}, interface{}, ...*options.UpdateOptions) (*mongo.UpdateResult, error) ReplaceOne(context.Context, interface{}, interface{}, ...*options.ReplaceOptions) (*mongo.UpdateResult, error) FindOneAndUpdate(context.Context, interface{}, interface{}, ...*options.FindOneAndUpdateOptions) *mongo.SingleResult Aggregate(context.Context, interface{}, ...*options.AggregateOptions) (*mongo.Cursor, error) CountDocuments(context.Context, interface{}, ...*mgoOtions.CountOptions) (int64, error) }
CollectionAPI is the internal Collection API interface
type CursorAPI ¶
type CursorAPI interface { Next(context.Context) bool All(context.Context, interface{}) error Decode(interface{}) error }
CursorAPI is the internal Cursor API interface
type IndexAPI ¶
type IndexAPI interface { ListSpecifications(ctx context.Context, opts ...*options.ListIndexesOptions) ([]*mongo.IndexSpecification, error) DropOne(ctx context.Context, name string, opts ...*options.DropIndexesOptions) (bson.Raw, error) CreateOne(context.Context, mongo.IndexModel, ...*options.CreateIndexesOptions) (string, error) CreateMany(context.Context, []mongo.IndexModel, ...*options.CreateIndexesOptions) ([]string, error) }
IndexAPI is the internal Index API interface
type MockClient ¶
type MockClient struct { ClientAPI ErrConnect error ErrPing error ErrInsertOne error ErrBulkWrite error InsertOneResult mongo.InsertOneResult BulkWriteResult mongo.BulkWriteResult ErrFind error ErrDeleteOne error ErrDeleteMany error ErrorCursorAll error ErrUpdateOne error ErrReplaceOne error UpdateOneResult mongo.UpdateResult ReplaceOneResult mongo.UpdateResult FindOneAndUpdateResult mongo.SingleResult ErrorSingleResultDecode error AggregateResult mongo.Cursor ErrAggregate error CreateIndexResult string CreateManyIndexResult []string ErrCreateIndex error ErrCreateManyIndex error ListSpecificationResult []*mongo.IndexSpecification ErrListSpecifications error DropOneResult bson.Raw ErrDropOne error CountResult int64 ErrCount error }
MockClient is the internal mock client
func (*MockClient) Connect ¶
func (p *MockClient) Connect(ctx context.Context) error
Connect is an internal mock method
func (*MockClient) GetCollection ¶
func (p *MockClient) GetCollection() CollectionAPI
GetCollection is an internal mock method
func (*MockClient) SetCollection ¶
func (p *MockClient) SetCollection(collection string)
SetCollection is an internal mock method
func (*MockClient) SetCursor ¶
func (p *MockClient) SetCursor(*mongo.Cursor) CursorAPI
SetCursor is an internal mock method
func (*MockClient) SetSingleResult ¶
func (p *MockClient) SetSingleResult(*mongo.SingleResult) SingleResultAPI
SetSingleResult is an internal mock method
type MockCollection ¶
type MockCollection struct { CollectionAPI ErrInsertOne error ErrBulkWrite error ErrFind error ErrDeleteOne error ErrDeleteMany error InsertOneResult mongo.InsertOneResult BulkWriteResult mongo.BulkWriteResult DeleteResult mongo.DeleteResult ErrUpdateOne error ErrReplaceOne error UpdateOneResult mongo.UpdateResult ReplaceOneResult mongo.UpdateResult FindOneAndUpdateResult mongo.SingleResult AggregateResult mongo.Cursor ErrAggregate error CreateIndexResult string CreateManyIndexResult []string ErrCreateIndex error ErrCreateManyIndex error ListSpecificationResult []*mongo.IndexSpecification ErrListSpecifications error DropOneResult bson.Raw ErrDropOne error CountResult int64 ErrCount error }
MockCollection is the internal mock collection
func (*MockCollection) Aggregate ¶
func (c *MockCollection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
Aggregate is an internal mock method
func (*MockCollection) BulkWrite ¶
func (c *MockCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*mgoOtions.BulkWriteOptions) (*mongo.BulkWriteResult, error)
BulkWrite is an internal mock method
func (*MockCollection) CountDocuments ¶ added in v0.15.0
func (c *MockCollection) CountDocuments(context.Context, interface{}, ...*mgoOtions.CountOptions) (int64, error)
CountDocuments is an internal mock method
func (*MockCollection) DeleteMany ¶
func (c *MockCollection) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
DeleteMany is an internal mock method
func (*MockCollection) DeleteOne ¶
func (c *MockCollection) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
DeleteOne is an internal mock method
func (*MockCollection) Find ¶
func (c *MockCollection) Find(ctx context.Context, filter interface{}, opts ...*mgoOtions.FindOptions) (*mongo.Cursor, error)
Find is an internal mock method
func (*MockCollection) FindOneAndUpdate ¶
func (c *MockCollection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
FindOneAndUpdate is an internal mock method
func (*MockCollection) GetIndex ¶
func (c *MockCollection) GetIndex() IndexAPI
GetIndex is an internal mock method
func (*MockCollection) InsertOne ¶
func (c *MockCollection) InsertOne(ctx context.Context, document interface{}, opts ...*mgoOtions.InsertOneOptions) (*mongo.InsertOneResult, error)
InsertOne is an internal mock method
func (*MockCollection) ReplaceOne ¶
func (c *MockCollection) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
ReplaceOne is an internal mock method
func (*MockCollection) UpdateOne ¶
func (c *MockCollection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateOne is an internal mock method
type MockCursor ¶
MockCursor is the internal mock cursor
func (*MockCursor) All ¶
func (c *MockCursor) All(ctx context.Context, results interface{}) error
All is an internal mock method
func (*MockCursor) Decode ¶
func (c *MockCursor) Decode(v interface{}) error
Decode is an internal mock method
type MockIndex ¶
type MockIndex struct { CursorAPI CreateIndexResult string CreateManyIndexResult []string ListSpecificationResult []*mongo.IndexSpecification DropOneResult bson.Raw ErrCreateIndex error ErrCreateManyIndex error ErrListSpecifications error ErrDropOne error }
MockIndex is the internal mock index
func (*MockIndex) CreateMany ¶ added in v0.13.4
func (i *MockIndex) CreateMany(_ context.Context, _ []mongo.IndexModel, _ ...*options.CreateIndexesOptions) ([]string, error)
CreateMany is an internal mock method
func (*MockIndex) CreateOne ¶
func (i *MockIndex) CreateOne(_ context.Context, _ mongo.IndexModel, _ ...*options.CreateIndexesOptions) (string, error)
CreateOne is an internal mock method
func (*MockIndex) DropOne ¶ added in v0.13.0
func (i *MockIndex) DropOne(_ context.Context, _ string, _ ...*options.DropIndexesOptions) (bson.Raw, error)
DropOne is an internal mock method
func (*MockIndex) ListSpecifications ¶ added in v0.13.0
func (i *MockIndex) ListSpecifications(_ context.Context, _ ...*options.ListIndexesOptions) ([]*mongo.IndexSpecification, error)
ListSpecifications is an internal mock method
type MockSingleResult ¶
type MockSingleResult struct { SingleResultAPI ErrorSingleResultDecode error }
MockSingleResult is the internal mock single result
func (*MockSingleResult) Decode ¶
func (s *MockSingleResult) Decode(v interface{}) error
Decode is an internal mock method
type MockbsonReader ¶ added in v0.8.0
type MockbsonReader struct { bsonrw.ValueReader ErrReadDateTime error }
MockbsonReader structure used by codec
func (*MockbsonReader) ReadDateTime ¶ added in v0.8.0
func (b *MockbsonReader) ReadDateTime() (int64, error)
ReadDateTime API
type MockbsonWriter ¶
type MockbsonWriter struct {
bsonrw.ValueWriter
}
MockbsonWriter structure used by codec
func (*MockbsonWriter) WriteDateTime ¶
func (b *MockbsonWriter) WriteDateTime(dt int64) error
WriteDateTime API
func (*MockbsonWriter) WriteString ¶ added in v0.13.3
func (b *MockbsonWriter) WriteString(string) error
WriteDateTime API
type Mongo ¶
type Mongo struct { // Username for database authentication Username string `mapstructure:"username"` // Password for database authentication Password string `mapstructure:"password"` // Name of the database Name string `mapstructure:"name"` // URL of the database URL string `mapstructure:"url"` // Name of the authorisation database AuthSource string `mapstructure:"authSource"` }
Mongo input structure
type MongoAPI ¶
type MongoAPI interface { SetCollection(string) MongoAPI SetOptions(...Option) MongoAPI Connect() error CountDocuments(interface{}, *int64, ...*options.CountOptions) error Get(interface{}, interface{}, ...*options.FindOptions) error Insert(interface{}) error InsertBulk([]*mongo.UpdateOneModel) error Delete(interface{}) error DeleteAll() error Update(interface{}, interface{}) error Upsert(interface{}, interface{}) error FindAndUpdate(interface{}, interface{}, interface{}) error Aggregate(mongo.Pipeline, interface{}) error CreateIndexes(mongo.IndexModel) error CreateManyIndexes([]mongo.IndexModel) error ListIndexes() ([]string, error) DropIndex(string) error Incr(string) (int64, error) }
MongoAPI is the public Mongo API interface
type MongoDB ¶
type MongoDB struct { ClientAPI // From user selection Collection string // contains filtered or unexported fields }
MongoDB is the public Mongo Instance
func (*MongoDB) CountDocuments ¶ added in v0.15.0
func (m *MongoDB) CountDocuments(filter interface{}, count *int64, countOptions ...*options.CountOptions) (err error)
func (*MongoDB) CreateIndexes ¶
func (m *MongoDB) CreateIndexes(opt mongo.IndexModel) error
CreateIndexes create index based on input mongo index model
func (*MongoDB) CreateManyIndexes ¶ added in v0.13.4
func (m *MongoDB) CreateManyIndexes(opt []mongo.IndexModel) error
CreateManyIndexes create indexes based on input mongo index model array
func (*MongoDB) FindAndUpdate ¶
FindAndUpdate single document from a collection based on filter input
func (*MongoDB) Get ¶
func (m *MongoDB) Get(filter interface{}, data interface{}, findOptions ...*options.FindOptions) error
Get return documents from collection based on input filter
func (*MongoDB) InsertBulk ¶
func (m *MongoDB) InsertBulk(operations []*mongo.UpdateOneModel) error
InsertBulk multiple documents value inside collection
func (*MongoDB) ListIndexes ¶ added in v0.13.0
ListIndexes list indexes
func (*MongoDB) SetCollection ¶
SetCollection set collection name for the public client
func (*MongoDB) SetOptions ¶
SetOptions set options for the public client
type SingleResultAPI ¶
type SingleResultAPI interface {
Decode(interface{}) error
}
SingleResultAPI is the internal Single Result API interface