Skip to content

Commit

Permalink
Add NewCursorFromDocuments and NewSingleResultFromDocument functions (#…
Browse files Browse the repository at this point in the history
…56)

* Add NewCursorFromDocuments and NewSingleResultFromDocument functions

* Remove uneeded tools from the Brewfile
  • Loading branch information
SVilgelm authored Apr 9, 2022
1 parent 0cc1160 commit 31ff8de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .github/Brewfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
tap "golangci/tap"
tap "kyoh86/tap"
tap "sv-tools/apps"

# Fast linters runner for Go.
brew "golangci/tap/golangci-lint"
# Rich-Go will enrich `go test` outputs with text decorations
brew "kyoh86/tap/richgo"
# bumptag is a tool to increment a version and to create a git tag with an annotation.
brew "sv-tools/apps/bumptag"

# App to build and share containerized applications and microservices
cask "docker"
11 changes: 11 additions & 0 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/mongo"
)

Expand Down Expand Up @@ -64,3 +65,13 @@ func (c *cursor) TryNext(ctx context.Context) bool {
func wrapCursor(cr *mongo.Cursor) Cursor {
return &cursor{cr: cr}
}

// NewCursorFromDocuments is a wrapper for NewCursorFromDocuments function of the mongodb to return Cursor
// https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#NewCursorFromDocuments
func NewCursorFromDocuments(documents []interface{}, err error, registry *bsoncodec.Registry) (Cursor, error) {
cr, err := mongo.NewCursorFromDocuments(documents, err, registry)
if err != nil {
return nil, err
}
return wrapCursor(cr), nil
}
9 changes: 9 additions & 0 deletions single_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mongoifc

import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/mongo"
)

Expand Down Expand Up @@ -32,3 +33,11 @@ func (s *singleResult) Err() error {
func wrapSingleResult(sr *mongo.SingleResult) SingleResult {
return &singleResult{sr: sr}
}

// NewSingleResultFromDocument is a wrapper for NewSingleResultFromDocument function of the mongodb
// to return SingleResult
// https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#NewSingleResultFromDocument
func NewSingleResultFromDocument(document interface{}, err error, registry *bsoncodec.Registry) SingleResult {
sr := mongo.NewSingleResultFromDocument(document, err, registry)
return wrapSingleResult(sr)
}

0 comments on commit 31ff8de

Please sign in to comment.