MCPcopy Create free account
hub / github.com/Permify/permify / Operation

Function Operation

pkg/bundle/bundle.go:13–158  ·  view source on GitHub ↗
(arguments map[string]string, operation *base.Operation)

Source from the content-addressed store, hash-verified

11)
12
13func Operation(arguments map[string]string, operation *base.Operation) (tb database.TupleBundle, ab database.AttributeBundle, err error) {
14 rWrites := operation.GetRelationshipsWrite()
15
16 // Initialize a TupleCollection to store the processed tuples.
17 var wtc database.TupleCollection
18
19 // Iterate over each write operation.
20 for _, w := range rWrites {
21 // Parse the write operation string into a template.
22 tmpl, err := template.New("template").Option("missingkey=zero").Parse(w)
23 if err != nil {
24 return tb, ab, err
25 }
26
27 // Create a buffer to hold the template execution output.
28 var buf bytes.Buffer
29
30 // Execute the template with the provided arguments and store the output in the buffer.
31 err = tmpl.Execute(&buf, arguments)
32 if err != nil {
33 return tb, ab, err
34 }
35
36 // Convert the write string into a tuple.
37 t, err := tuple.Tuple(buf.String())
38 if err != nil {
39 return tb, ab, err
40 }
41
42 // Add the tuple to the write tuple collection.
43 wtc.Add(t)
44 }
45
46 // Assign the processed write tuples to the tuple bundle.
47 tb.Write = wtc
48
49 // Retrieve the delete operations from the operation object.
50 rDeletes := operation.GetRelationshipsDelete()
51
52 // Initialize a TupleCollection to store the delete tuples.
53 var dtc database.TupleCollection
54
55 // Iterate over each delete operation.
56 for _, w := range rDeletes {
57 // Parse the write operation string into a template.
58 tmpl, err := template.New("template").Option("missingkey=zero").Parse(w)
59 if err != nil {
60 return tb, ab, err
61 }
62
63 // Create a buffer to hold the template execution output.
64 var buf bytes.Buffer
65
66 // Execute the template with the provided arguments and store the output in the buffer.
67 err = tmpl.Execute(&buf, arguments)
68 if err != nil {
69 return tb, ab, err
70 }

Callers 3

runBundleMethod · 0.92
RunBundleMethod · 0.92
bundle_test.goFile · 0.70

Calls 10

AddMethod · 0.95
AddMethod · 0.95
TupleFunction · 0.92
AttributeFunction · 0.92
GetRelationshipsWriteMethod · 0.80
ParseMethod · 0.80
GetAttributesWriteMethod · 0.80
GetAttributesDeleteMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected