Add mongo client interfaces

This commit is contained in:
Nikita Tokarchuk
2020-02-26 23:33:17 +01:00
parent e681af6dea
commit c5fab32e49
11 changed files with 114 additions and 57 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ import (
"github.com/mainnika/mongox-go-driver/mongox/query"
)
func createSimpleLoad(db *mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
func createSimpleLoad(db mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
collection := db.GetCollectionOf(target)
opts := options.Find()
@@ -26,7 +26,7 @@ func createSimpleLoad(db *mongox.Database, target interface{}, composed *query.Q
return collection.Find(db.Context(), composed.M(), opts)
}
func createAggregateLoad(db *mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
func createAggregateLoad(db mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
collection := db.GetCollectionOf(target)
opts := options.Aggregate()
+1 -1
View File
@@ -11,7 +11,7 @@ import (
// Count function counts documents in the database by query
// target is used only to get collection by tag so it'd be better to use nil ptr here
func Count(db *mongox.Database, target interface{}, filters ...interface{}) (int64, error) {
func Count(db mongox.Database, target interface{}, filters ...interface{}) (int64, error) {
collection := db.GetCollectionOf(target)
opts := options.Count()
+1 -1
View File
@@ -12,7 +12,7 @@ import (
)
// DeleteArray removes documents list from a database by their ids
func DeleteArray(db *mongox.Database, target interface{}) error {
func DeleteArray(db mongox.Database, target interface{}) error {
targetV := reflect.ValueOf(target)
targetT := targetV.Type()
+1 -1
View File
@@ -14,7 +14,7 @@ import (
)
// DeleteOne removes a document from a database and then returns it into target
func DeleteOne(db *mongox.Database, target interface{}, filters ...interface{}) error {
func DeleteOne(db mongox.Database, target interface{}, filters ...interface{}) error {
collection := db.GetCollectionOf(target)
opts := &options.FindOneAndDeleteOptions{}
+1 -1
View File
@@ -12,7 +12,7 @@ import (
)
// LoadArray loads an array of documents from the database by query
func LoadArray(db *mongox.Database, target interface{}, filters ...interface{}) error {
func LoadArray(db mongox.Database, target interface{}, filters ...interface{}) error {
targetV := reflect.ValueOf(target)
targetT := targetV.Type()
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
// LoadOne function loads a first single target document by a query
func LoadOne(db *mongox.Database, target interface{}, filters ...interface{}) error {
func LoadOne(db mongox.Database, target interface{}, filters ...interface{}) error {
composed := query.Compose(append(filters, query.Limit(1))...)
hasPreloader, _ := composed.Preloader()
+1 -1
View File
@@ -55,7 +55,7 @@ func (l *StreamLoader) Close() error {
}
// LoadStream function loads documents one by one into a target channel
func LoadStream(db *mongox.Database, target interface{}, filters ...interface{}) (*StreamLoader, error) {
func LoadStream(db mongox.Database, target interface{}, filters ...interface{}) (*StreamLoader, error) {
var cursor *mongo.Cursor
var err error
+1 -1
View File
@@ -14,7 +14,7 @@ import (
)
// SaveOne saves a single source document to the database
func SaveOne(db *mongox.Database, source interface{}) error {
func SaveOne(db mongox.Database, source interface{}) error {
collection := db.GetCollectionOf(source)
opts := options.FindOneAndReplace()