MCPcopy
hub / github.com/dosco/graphjin / executeManagedQuery

Method executeManagedQuery

core/managed_query.go:74–138  ·  view source on GitHub ↗
(c context.Context)

Source from the content-addressed store, hash-verified

72}
73
74func (s *gstate) executeManagedQuery(c context.Context) (bool, error) {
75 if s.r.operation != qcode.QTQuery || s.cs == nil || s.cs.st.qc == nil {
76 return false, nil
77 }
78
79 dbName := s.database
80 if dbName == "" {
81 dbName = s.gj.defaultDB
82 }
83 handler := s.gj.managedQueryHandlers[dbName]
84 if handler == nil {
85 return false, nil
86 }
87
88 managedTables := make(map[string]struct{})
89 for _, table := range handler.ManagedQueryTables() {
90 managedTables[strings.ToLower(table.Name)] = struct{}{}
91 }
92
93 qc := s.cs.st.qc
94 var managedRoots, normalRoots int
95 for _, rootID := range qc.Roots {
96 sel := qc.Selects[rootID]
97 if _, ok := managedTables[strings.ToLower(sel.Ti.Name)]; ok {
98 managedRoots++
99 } else {
100 normalRoots++
101 }
102 }
103
104 if managedRoots == 0 {
105 return false, nil
106 }
107 if normalRoots != 0 {
108 return true, fmt.Errorf("GraphJin system roots cannot be mixed with normal database roots; run discovery/control-plane calls separately")
109 }
110
111 req := ManagedQueryRequest{
112 Database: dbName,
113 Roots: make([]ManagedQueryRoot, 0, len(qc.Roots)),
114 }
115 for _, rootID := range qc.Roots {
116 sel := qc.Selects[rootID]
117 root := ManagedQueryRoot{
118 FieldName: sel.FieldName,
119 Table: sel.Ti.Name,
120 Fields: managedSelectedFields(sel.Fields),
121 Where: managedFilterToValue(sel.Where.Exp, s.vmap),
122 OrderBy: managedOrderBy(sel.OrderBy),
123 Limit: int(sel.Paging.Limit),
124 Offset: int(sel.Paging.Offset),
125 }
126 req.Roots = append(req.Roots, root)
127 }
128
129 data, err := handler.ExecuteManagedQuery(c, req)
130 if err != nil {
131 return true, err

Callers 1

compileAndExecuteMethod · 0.95

Calls 6

managedSelectedFieldsFunction · 0.85
managedFilterToValueFunction · 0.85
managedOrderByFunction · 0.85
encryptValuesFunction · 0.85
ManagedQueryTablesMethod · 0.65
ExecuteManagedQueryMethod · 0.65

Tested by

no test coverage detected