Skip to content

Commit

Permalink
add find collation option (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghao-bianjie authored Aug 28, 2022
1 parent 48e2abe commit 2b58f9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package qmgo

import "go.mongodb.org/mongo-driver/mongo/options"

// CollectionI
// 集合操作接口
//type CollectionI interface {
Expand Down Expand Up @@ -48,6 +50,7 @@ type CursorI interface {

// QueryI Query interface
type QueryI interface {
Collation(collation *options.Collation) QueryI
Sort(fields ...string) QueryI
Select(selector interface{}) QueryI
Skip(n int64) QueryI
Expand Down
13 changes: 13 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ type Query struct {
skip *int64
batchSize *int64
noCursorTimeout *bool
collation *options.Collation

ctx context.Context
collection *mongo.Collection
opts []qOpts.FindOptions
registry *bsoncodec.Registry
}

func (q *Query) Collation(collation *options.Collation) QueryI {
newQ := q
newQ.collation = collation
return newQ
}

func (q *Query) NoCursorTimeout(n bool) QueryI {
newQ := q
newQ.noCursorTimeout = &n
Expand Down Expand Up @@ -128,6 +135,9 @@ func (q *Query) One(result interface{}) error {
}
opt := options.FindOne()

if q.collation != nil {
opt.SetCollation(q.collation)
}
if q.sort != nil {
opt.SetSort(q.sort)
}
Expand Down Expand Up @@ -163,6 +173,9 @@ func (q *Query) All(result interface{}) error {
}
}
opt := options.Find()
if q.collation != nil {
opt.SetCollation(q.collation)
}
if q.sort != nil {
opt.SetSort(q.sort)
}
Expand Down

0 comments on commit 2b58f9a

Please sign in to comment.