Skip to content

Commit

Permalink
Update mongo driver
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Mar 23, 2019
1 parent 518a830 commit 4ee2913
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
version = "1.10.0"

[[constraint]]
name = "github.com/mongodb/mongo-go-driver"
version = "0.3.0"
name = "go.mongodb.org/mongo-driver"
version = "1.0.0"

[[constraint]]
name = "gopkg.in/yaml.v2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ SELECT name, city, state FROM users WHERE (name IN (?,?) AND grade NOT BETWEEN ?

##### mongo.Walk

The `walkers` `mongo` package include a helper mongo.Walk ([code](/pkg/walkers/mongo/walk.go), [doc](https://godoc.org/github.com/yaacov/tree-search-language/pkg/walkers/mongo#Walk)) method that adds search bson filter to [mongo-go-driver](https://github.com/mongodb/mongo-go-driver):
The `walkers` `mongo` package include a helper mongo.Walk ([code](/pkg/walkers/mongo/walk.go), [doc](https://godoc.org/github.com/yaacov/tree-search-language/pkg/walkers/mongo#Walk)) method that adds search bson filter to [mongo-go-driver](https://go.mongodb.org/mongo-driver):

``` go
import (
Expand Down
4 changes: 2 additions & 2 deletions cmd/tsl_mongo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"fmt"
"log"

"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/yaacov/tree-search-language/pkg/tsl"
"github.com/yaacov/tree-search-language/pkg/walkers/ident"
walker "github.com/yaacov/tree-search-language/pkg/walkers/mongo"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"

"github.com/yaacov/tree-search-language/cmd/model"
)
Expand Down
5 changes: 3 additions & 2 deletions cmd/tsl_mongo/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package main
import (
"context"

"github.com/mongodb/mongo-go-driver/mongo"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/yaacov/tree-search-language/cmd/model"
)

func connect(ctx context.Context, url string) (client *mongo.Client, err error) {
client, err = mongo.NewClient(url)
client, err = mongo.NewClient(options.Client().ApplyURI(url))
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ require (
github.com/mattn/go-colorable v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mattn/go-sqlite3 v1.10.0
github.com/mongodb/mongo-go-driver v0.3.0
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect
go.mongodb.org/mongo-driver v1.0.0
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/walkers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The `sql` package include a helper `sql.Walk` ([code](/pkg/walkers/sql/walk.go),

##### mongo

The `mongo` package include a helper `mongo.Walk` ([code](/pkg/walkers/mongo/walk.go), [doc](https://godoc.org/github.com/yaacov/tree-search-language/pkg/walkers/mongo#Walk)) method that adds search `bson` filter to [mongo-go-driver](https://github.com/mongodb/mongo-go-driver).
The `mongo` package include a helper `mongo.Walk` ([code](/pkg/walkers/mongo/walk.go), [doc](https://godoc.org/github.com/yaacov/tree-search-language/pkg/walkers/mongo#Walk)) method that adds search `bson` filter to [mongo-go-driver](https://go.mongodb.org/mongo-driver).

##### graphviz

Expand Down
2 changes: 1 addition & 1 deletion pkg/walkers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
//
// squirrel: https://github.com/Masterminds/squirrel
//
// mongo-go-driver: https://github.com/mongodb/mongo-go-driver
// mongo-go-driver: https://go.mongodb.org/mongo-driver
package walkers
6 changes: 3 additions & 3 deletions pkg/walkers/mongo/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package mongo

import (
"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"

"github.com/yaacov/tree-search-language/pkg/tsl"
)
Expand Down Expand Up @@ -74,7 +74,7 @@ func bsonFromArray(a interface{}) (values []interface{}, err error) {
// // Run query
// cur, _ := collection.Find(ctx, filter)
//
// mongo-go-driver: https://github.com/mongodb/mongo-go-driver
// mongo-go-driver: https://go.mongodb.org/mongo-driver
//
func Walk(n tsl.Node) (b bson.D, err error) {
var values []interface{}
Expand Down
7 changes: 7 additions & 0 deletions pkg/walkers/semantics/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

// EvalFunc is a key evaluation function type.
//
// The function gets a key (string), and returns the value (interface{}) stored in the data document for that key.
type EvalFunc = func(string) (interface{}, bool)

// Walk travel the TSL tree and implements search semantics.
Expand All @@ -44,6 +46,11 @@ type EvalFunc = func(string) (interface{}, bool)
//
// // evalFactory creates an evaluation function for a data record.
// func evalFactory(r map[string]string) semantics.EvalFunc {
// // Returns:
// // A function (semantics.EvalFunc) that gets a `key` for a record and returns
// // the value of the document for that key.
// // If no value can be found for this `key` in our record, it will return
// // ok = false, if value is found it will return ok = true.
// return func(k string) (interface{}, bool) {
// v, ok := r[k]
// return v, ok
Expand Down

0 comments on commit 4ee2913

Please sign in to comment.