5 Commits

Author SHA1 Message Date
Nikita Tokarchuk 9cf3551c20 MIT licensed 2020-06-04 21:30:19 +02:00
Nikita Tokarchuk 3035d8d571 Fix aggregation pipeline match step 2020-06-04 18:15:59 +02:00
Nikita Tokarchuk eac50d1770 Do not use unnecessary reflect 2020-06-04 18:15:35 +02:00
Nikita Tokarchuk 05ebb25e70 Use unsafe pointer in the interface struct header is more correct way 2020-06-04 18:15:08 +02:00
Nikita Tokarchuk fd53c66690 Use ordered document for index model 2020-03-25 17:40:26 +01:00
5 changed files with 28 additions and 13 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright © 2020 Nikita Tokarchuk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1 -1
View File
@@ -111,7 +111,7 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query
pipeline := primitive.A{}
if !composed.Empty() {
pipeline = append(pipeline, primitive.M{"$match": primitive.M{"$expr": composed.M()}})
pipeline = append(pipeline, primitive.M{"$match": composed.M()})
}
if composed.Sorter() != nil {
pipeline = append(pipeline, primitive.M{"$sort": composed.Sorter()})
+4 -4
View File
@@ -64,15 +64,15 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error {
panic(fmt.Errorf("cannot evaluate index key"))
}
index := primitive.M{key: 1}
opts := &options.IndexOptions{
Background: &f,
Unique: &f,
Name: &name,
}
index := primitive.D{{Key: key, Value: 1}}
if indexValues[0] == "-" {
index[key] = -1
index = primitive.D{{Key: key, Value: -1}}
}
for _, prop := range indexValues[1:] {
@@ -114,9 +114,9 @@ func (d *Database) IndexEnsure(cfg interface{}, document interface{}) error {
}
if compoundValue[0] == '-' {
index[compoundValue[1:]] = -1
index = append(index, primitive.E{compoundValue[1:], -1})
} else {
index[compoundValue] = 1
index = append(index, primitive.E{compoundValue, 1})
}
default:
+1 -7
View File
@@ -2,8 +2,6 @@ package query
import (
"go.mongodb.org/mongo-driver/bson"
"reflect"
)
// Query is an enchanched bson.M map
@@ -82,11 +80,7 @@ func (q *Query) Preloader() (empty bool, preloader []string) {
// Empty checks the query for any content
func (q *Query) Empty() bool {
qv := reflect.ValueOf(q.m)
keys := qv.MapKeys()
return len(keys) == 0
return len(q.m) == 0
}
// M returns underlying query map
+1 -1
View File
@@ -8,7 +8,7 @@ import (
func IsNil(i interface{}) bool {
type iface struct {
_ *interface{}
_ unsafe.Pointer
ptr unsafe.Pointer
}