Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NamesOf to the BatchQuadStore interface #742

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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