package storage import ( "context" "local/dndex/storage/entity" "local/dndex/storage/operator" "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, namespace string, from ...string) ([]entity.One, error) { filter := operator.NewFilterIn("_id", from) ch, err := g.mongo.Find(ctx, namespace, filter) if err != nil { return nil, err } var ones []entity.One for one := range ch { var o entity.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, namespace string, one entity.One) error { return g.mongo.Insert(ctx, namespace, one) } func (g Graph) Update(ctx context.Context, namespace string, one entity.One, modify interface{}) error { return g.mongo.Update(ctx, namespace, one, modify) } func (g Graph) Delete(ctx context.Context, namespace string, filter interface{}) error { return g.mongo.Delete(ctx, namespace, filter) }