mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-07-03 17:22:33 +00:00
Use primitive import instead of bson alias
This commit is contained in:
@@ -3,7 +3,6 @@ package database
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"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...)
|
composed := query.Compose(filters...)
|
||||||
ctx := query.WithContext(d.Context(), composed)
|
ctx := query.WithContext(d.Context(), composed)
|
||||||
|
|
||||||
composed.And(bson.M{"_id": id})
|
composed.And(primitive.M{"_id": id})
|
||||||
|
|
||||||
opts.SetUpsert(true)
|
opts.SetUpsert(true)
|
||||||
opts.SetReturnDocument(options.After)
|
opts.SetReturnDocument(options.After)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/modern-go/reflect2"
|
"github.com/modern-go/reflect2"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
|
||||||
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
|
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
|
||||||
@@ -44,10 +43,10 @@ func Push(q *Query, f interface{}) (ok bool) {
|
|||||||
return ok
|
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) {
|
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)
|
q.And(f)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package query
|
package query
|
||||||
|
|
||||||
import (
|
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 {
|
type Query struct {
|
||||||
m bson.M
|
m primitive.M
|
||||||
limiter Limiter
|
limiter Limiter
|
||||||
sorter Sorter
|
sorter Sorter
|
||||||
skipper Skipper
|
skipper Skipper
|
||||||
@@ -17,16 +17,16 @@ type Query struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// And function pushes the elem query to the $and array of the query
|
// 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 {
|
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 {
|
if !exists {
|
||||||
q.m["$and"] = bson.A{elem}
|
q.m["$and"] = primitive.A{elem}
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ func (q *Query) Skipper() (skip *int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Updater is an update command for a query
|
// 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 {
|
if q.updater == nil {
|
||||||
return
|
return
|
||||||
@@ -103,6 +103,6 @@ func (q *Query) Empty() (isEmpty bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// M returns underlying query map
|
// M returns underlying query map
|
||||||
func (q *Query) M() (m bson.M) {
|
func (q *Query) M() (m primitive.M) {
|
||||||
return q.m
|
return q.m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package query
|
package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sorter is a filter to sort the data before query
|
// Sorter is a filter to sort the data before query
|
||||||
type Sorter interface {
|
type Sorter interface {
|
||||||
Sort() (sort bson.M)
|
Sort() (sort primitive.M)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort is a simple implementations of the Sorter filter
|
// Sort is a simple implementations of the Sorter filter
|
||||||
type Sort bson.M
|
type Sort primitive.M
|
||||||
|
|
||||||
var _ Sorter = &Sort{}
|
var _ Sorter = &Sort{}
|
||||||
|
|
||||||
// Sort returns a slice of fields which have to be sorted
|
// Sort returns a slice of fields which have to be sorted
|
||||||
func (f Sort) Sort() (sort bson.M) {
|
func (f Sort) Sort() (sort primitive.M) {
|
||||||
return bson.M(f)
|
return primitive.M(f)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package query
|
package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Updater is a filter to update the data
|
// Updater is a filter to update the data
|
||||||
type Updater interface {
|
type Updater interface {
|
||||||
Update() (update bson.A)
|
Update() (update primitive.A)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is a simple implementations of the Updater filter
|
// Update is a simple implementations of the Updater filter
|
||||||
type Update bson.M
|
type Update primitive.M
|
||||||
|
|
||||||
var _ Updater = &Update{}
|
var _ Updater = &Update{}
|
||||||
|
|
||||||
// Update returns an update command
|
// Update returns an update command
|
||||||
func (u Update) Update() (update bson.A) {
|
func (u Update) Update() (update primitive.A) {
|
||||||
return bson.A{bson.M(u)}
|
return primitive.A{primitive.M(u)}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user