Impl storage mongo driver and config
This commit is contained in:
43
storage/graph.go
Normal file
43
storage/graph.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user