Skip to content

Commit

Permalink
Fixing issue in psql driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Mar 29, 2021
1 parent e92f83e commit bce6abc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
18 changes: 9 additions & 9 deletions psql/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (g *Graph) GetVertex(gid string, load bool) *gdbi.Vertex {
log.WithFields(log.Fields{"error": err}).Error("GetVertex: convertVertexRow")
return nil
}
return gdbi.NewElementFromVertex(vertex)
return vertex
}

// GetEdge loads an edge given an id. It returns a nil if not found.
Expand All @@ -207,7 +207,7 @@ func (g *Graph) GetEdge(gid string, load bool) *gdbi.Edge {
log.WithFields(log.Fields{"error": err}).Error("GetEdge: convertEdgeRow")
return nil
}
return gdbi.NewElementFromEdge(edge)
return edge
}

// GetVertexList produces a channel of all vertices in the graph
Expand Down Expand Up @@ -236,7 +236,7 @@ func (g *Graph) GetVertexList(ctx context.Context, load bool) <-chan *gdbi.Verte
log.WithFields(log.Fields{"error": err}).Error("GetVertexList: convertVertexRow")
continue
}
o <- gdbi.NewElementFromVertex(v)
o <- v
}
if err := rows.Err(); err != nil {
log.WithFields(log.Fields{"error": err}).Error("GetVertexList: iterating")
Expand Down Expand Up @@ -298,7 +298,7 @@ func (g *Graph) GetEdgeList(ctx context.Context, load bool) <-chan *gdbi.Edge {
log.WithFields(log.Fields{"error": err}).Error("GetEdgeList: convertEdgeRow")
continue
}
o <- gdbi.NewElementFromEdge(e)
o <- e
}
if err := rows.Err(); err != nil {
log.WithFields(log.Fields{"error": err}).Error("GetEdgeList: iterating")
Expand Down Expand Up @@ -354,7 +354,7 @@ func (g *Graph) GetVertexChannel(ctx context.Context, reqChan chan gdbi.ElementL
log.WithFields(log.Fields{"error": err}).Error("GetVertexChannel: convertVertexRow")
continue
}
chunk[v.Gid] = gdbi.NewElementFromVertex(v)
chunk[v.ID] = v
}
if err := rows.Err(); err != nil {
log.WithFields(log.Fields{"error": err}).Error("GetVertexChannel: iterating")
Expand Down Expand Up @@ -455,7 +455,7 @@ func (g *Graph) GetOutChannel(ctx context.Context, reqChan chan gdbi.ElementLook
}
r := batchMap[vrow.From]
for _, ri := range r {
ri.Vertex = gdbi.NewElementFromVertex(v)
ri.Vertex = v
o <- ri
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ func (g *Graph) GetInChannel(ctx context.Context, reqChan chan gdbi.ElementLooku
}
r := batchMap[vrow.To]
for _, ri := range r {
ri.Vertex = gdbi.NewElementFromVertex(v)
ri.Vertex = v
o <- ri
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ func (g *Graph) GetOutEdgeChannel(ctx context.Context, reqChan chan gdbi.Element
}
r := batchMap[erow.From]
for _, ri := range r {
ri.Edge = gdbi.NewElementFromEdge(e)
ri.Edge = e
o <- ri
}
}
Expand Down Expand Up @@ -722,7 +722,7 @@ func (g *Graph) GetInEdgeChannel(ctx context.Context, reqChan chan gdbi.ElementL
}
r := batchMap[erow.To]
for _, ri := range r {
ri.Edge = gdbi.NewElementFromEdge(e)
ri.Edge = e
o <- ri
}
}
Expand Down
31 changes: 15 additions & 16 deletions psql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"fmt"
"regexp"

"github.com/bmeg/grip/gripql"
"google.golang.org/protobuf/types/known/structpb"
"github.com/bmeg/grip/gdbi"
)

type row struct {
Expand All @@ -17,38 +16,38 @@ type row struct {
Data []byte
}

func convertVertexRow(row *row, load bool) (*gripql.Vertex, error) {
func convertVertexRow(row *row, load bool) (*gdbi.Vertex, error) {
props := make(map[string]interface{})
if load {
err := json.Unmarshal(row.Data, &props)
if err != nil {
return nil, fmt.Errorf("unmarshal error: %v", err)
}
}
sProps, _ := structpb.NewStruct(props)
v := &gripql.Vertex{
Gid: row.Gid,
Label: row.Label,
Data: sProps,
v := &gdbi.Vertex{
ID: row.Gid,
Label: row.Label,
Data: props,
Loaded: load,
}
return v, nil
}

func convertEdgeRow(row *row, load bool) (*gripql.Edge, error) {
func convertEdgeRow(row *row, load bool) (*gdbi.Edge, error) {
props := make(map[string]interface{})
if load {
err := json.Unmarshal(row.Data, &props)
if err != nil {
return nil, fmt.Errorf("unmarshal error: %v", err)
}
}
sProps, _ := structpb.NewStruct(props)
e := &gripql.Edge{
Gid: row.Gid,
Label: row.Label,
From: row.From,
To: row.To,
Data: sProps,
e := &gdbi.Edge{
ID: row.Gid,
Label: row.Label,
From: row.From,
To: row.To,
Data: props,
Loaded: load,
}
return e, nil
}
Expand Down

0 comments on commit bce6abc

Please sign in to comment.