Use primitive import instead of bson alias

v2
Nikita Tokarchuk 4 years ago
parent f859828370
commit 0b798fe818
No known key found for this signature in database
GPG Key ID: DBFD964471BAE65C
  1. 3
      mongox/database/saveone.go
  2. 5
      mongox/query/compose.go
  3. 18
      mongox/query/query.go
  4. 10
      mongox/query/sort.go
  5. 10
      mongox/query/update.go

@ -3,7 +3,6 @@ package database
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
@ -21,7 +20,7 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
composed := query.Compose(filters...)
ctx := query.WithContext(d.Context(), composed)
composed.And(bson.M{"_id": id})
composed.And(primitive.M{"_id": id})
opts.SetUpsert(true)
opts.SetReturnDocument(options.After)

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/modern-go/reflect2"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
@ -44,10 +43,10 @@ func Push(q *Query, f interface{}) (ok bool) {
return ok
}
// applyBson is a fallback for a custom bson.M
// applyBson is a fallback for a custom primitive.M
func applyBson(q *Query, f interface{}) (ok bool) {
if f, ok := f.(bson.M); ok {
if f, ok := f.(primitive.M); ok {
q.And(f)
return true
}

@ -1,12 +1,12 @@
package query
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Query is an enchanched bson.M map
// Query is an enchanched primitive.M map
type Query struct {
m bson.M
m primitive.M
limiter Limiter
sorter Sorter
skipper Skipper
@ -17,16 +17,16 @@ type Query struct {
}
// And function pushes the elem query to the $and array of the query
func (q *Query) And(elem bson.M) (query *Query) {
func (q *Query) And(elem primitive.M) (query *Query) {
if q.m == nil {
q.m = bson.M{}
q.m = primitive.M{}
}
queries, exists := q.m["$and"].(bson.A)
queries, exists := q.m["$and"].(primitive.A)
if !exists {
q.m["$and"] = bson.A{elem}
q.m["$and"] = primitive.A{elem}
return q
}
@ -66,7 +66,7 @@ func (q *Query) Skipper() (skip *int64) {
}
// Updater is an update command for a query
func (q *Query) Updater() (update bson.A) {
func (q *Query) Updater() (update primitive.A) {
if q.updater == nil {
return
@ -103,6 +103,6 @@ func (q *Query) Empty() (isEmpty bool) {
}
// M returns underlying query map
func (q *Query) M() (m bson.M) {
func (q *Query) M() (m primitive.M) {
return q.m
}

@ -1,20 +1,20 @@
package query
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Sorter is a filter to sort the data before query
type Sorter interface {
Sort() (sort bson.M)
Sort() (sort primitive.M)
}
// Sort is a simple implementations of the Sorter filter
type Sort bson.M
type Sort primitive.M
var _ Sorter = &Sort{}
// Sort returns a slice of fields which have to be sorted
func (f Sort) Sort() (sort bson.M) {
return bson.M(f)
func (f Sort) Sort() (sort primitive.M) {
return primitive.M(f)
}

@ -1,20 +1,20 @@
package query
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Updater is a filter to update the data
type Updater interface {
Update() (update bson.A)
Update() (update primitive.A)
}
// Update is a simple implementations of the Updater filter
type Update bson.M
type Update primitive.M
var _ Updater = &Update{}
// Update returns an update command
func (u Update) Update() (update bson.A) {
return bson.A{bson.M(u)}
func (u Update) Update() (update primitive.A) {
return primitive.A{primitive.M(u)}
}

Loading…
Cancel
Save