Skip to content

Commit

Permalink
Add RefsOf to the BatchQuadStore interface
Browse files Browse the repository at this point in the history
Implement for kv/QuadStore to avoid breaking it's BatchQuadStore
implementation.
  • Loading branch information
Connor Newton authored and phyrwork committed Oct 18, 2018
1 parent 9652755 commit b378435
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions graph/kv/quadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@ func (qs *QuadStore) ValuesOf(ctx context.Context, vals []graph.Value) ([]quad.V
}
return out, last
}

func (qs *QuadStore) RefsOf(ctx context.Context, nodes []quad.Value) ([]graph.Value, error) {
values := make([]graph.Value, len(nodes))
err := View(qs.db, func(tx BucketTx) error {
for i, node := range nodes {
value, err := qs.resolveQuadValue(ctx, tx, node)
if err != nil {
return err
}
values[i] = Int64Value(value)
}
return nil
})
if err != nil {
return nil, err
}
return values, nil
}

func (qs *QuadStore) NameOf(v graph.Value) quad.Value {
ctx := context.TODO()
vals, err := qs.ValuesOf(ctx, []graph.Value{v})
Expand Down
16 changes: 16 additions & 0 deletions graph/quadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

type BatchQuadStore interface {
ValuesOf(ctx context.Context, vals []Value) ([]quad.Value, error)
RefsOf(ctx context.Context, nodes []quad.Value) ([]Value, error)
}

func ValuesOf(ctx context.Context, qs QuadStore, vals []Value) ([]quad.Value, error) {
Expand All @@ -45,6 +46,21 @@ func ValuesOf(ctx context.Context, qs QuadStore, vals []Value) ([]quad.Value, er
return out, nil
}

func RefsOf(ctx context.Context, qs QuadStore, nodes []quad.Value) ([]Value, error) {
if bq, ok := qs.(BatchQuadStore); ok {
return bq.RefsOf(ctx, nodes)
}
values := make([]Value, len(nodes))
for i, node := range nodes {
value := qs.ValueOf(node)
if value == nil {
return nil, fmt.Errorf("not found: %v", node)
}
values[i] = value
}
return values, nil
}

type QuadStore interface {
// The only way in is through building a transaction, which
// is done by a replication strategy.
Expand Down

0 comments on commit b378435

Please sign in to comment.