Impl storage mongo driver and config

This commit is contained in:
Bel LaPointe
2020-07-12 21:28:52 -06:00
parent 2c13814177
commit 1b051ee1d5
9 changed files with 461 additions and 0 deletions

43
storage/graph.go Normal file
View File

@@ -0,0 +1,43 @@
package storage
import (
"context"
"go.mongodb.org/mongo-driver/bson"
)
type Graph struct {
mongo Mongo
}
func NewGraph() Graph {
mongo := NewMongo()
return Graph{
mongo: mongo,
}
}
func (g Graph) List(ctx context.Context, from ...string) ([]One, error) {
filter := newFilterIn("_id", from)
ch, err := g.mongo.Find(ctx, filter)
if err != nil {
return nil, err
}
var ones []One
for one := range ch {
var o One
if err := bson.Unmarshal(one, &o); err != nil {
return nil, err
}
ones = append(ones, o)
}
return ones, nil
}
func (g Graph) Insert(ctx context.Context, one One) error {
return g.mongo.Insert(ctx, one)
}
func (g Graph) Update(ctx context.Context, one One, modify interface{}) error {
return g.mongo.Update(ctx, one, modify)
}