-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraverse.go
115 lines (110 loc) · 2.8 KB
/
traverse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package graph
import (
"github.com/aws/aws-sdk-go/service/dynamodb"
)
type traversalContext struct {
g *graph
err error
items []map[string]*dynamodb.AttributeValue
path []string
}
type traversalVertex struct {
v Vertex
e []Edge
}
type traversalEdge struct {
e Edge
}
//func (g *graph) GetVertices(Type, Id string) *traversalContext {
//
// graphId := Type + keyDelimiter + Id
//
// var t = traversalContext{
// err: nil,
// items: nil,
// g: g,
// path: []string{
// graphId,
// },
// }
//
// pCon := expr.Key(PartitionKeyName).Equal(expr.Value(graphId))
// sCon := expr.Key(SortKeyName).Equal(expr.Value(graphId))
// expr, err := expr.NewBuilder().
// WithKeyCondition(pCon.And(sCon)).
// Build()
// if err != nil {
// t.err = err
// return &t
// }
//
// output, err := g.dynamodb.Query(&dynamodb.QueryInput{
// KeyConditionExpression: expr.KeyCondition(),
// ExpressionAttributeNames: expr.Names(),
// ExpressionAttributeValues: expr.Values(),
// TableName: aws.String(g.tableName),
// });
// if err != nil {
// t.err = err
// return &t
// }
//
// t.items = output.Items
// return &t
//}
//
//func (t *traversalContext) As(out interface{}) *traversalContext {
// switch reflect.ValueOf(out).Elem().Kind() {
// case reflect.Struct, reflect.Map:
// if len(t.items) == 0 {
// t.err = fmt.Errorf("traversalContent.items is empty in call to As(", reflect.ValueOf(out).Kind().String(), ")")
// }
// t.err = dynamodbattribute.UnmarshalMap(t.items[0], out)
// case reflect.Array, reflect.Slice:
// t.err = dynamodbattribute.UnmarshalListOfMaps(t.items, out)
// }
// return t
//}
//
//func (t traversalContext) IsErr() error {
// return t.err
//}
//
//
//func (t *traversalContext) Out(label string, out interface{}) *traversalContext {
//
// graphId := Type + keyDelimiter + Id
// pCon := expr.Key(PartitionKeyName).Equal(expr.Value(graphId))
// sCon := expr.Key(SortKeyName).Equal(expr.Value(graphId))
// expr, err := expr.NewBuilder().
// WithKeyCondition(pCon.And(sCon)).
// Build()
// if err != nil {
// t.err = err
// return &t
// }
//
// output, err := g.dynamodb.Query(&dynamodb.QueryInput{
// KeyConditionExpression: expr.KeyCondition(),
// ExpressionAttributeNames: expr.Names(),
// ExpressionAttributeValues: expr.Values(),
// TableName: aws.String(g.tableName),
// });
// if err != nil {
// t.err = err
// return &t
// }
//
// t.items = output.Items
//
// switch reflect.ValueOf(out).Elem().Kind() {
// case reflect.Struct, reflect.Map:
// if len(t.items) == 0 {
// t.err = fmt.Errorf("traversalContent.items is empty in call to As(", reflect.ValueOf(out).Kind().String(), ")")
// }
// t.err = dynamodbattribute.UnmarshalMap(t.items[0], out)
// case reflect.Array, reflect.Slice:
// t.err = dynamodbattribute.UnmarshalListOfMaps(t.items, out)
// }
// return t
//}