MCPcopy Index your code
hub / github.com/bytebase/bytebase / GetQueryType

Function GetQueryType

backend/plugin/parser/mongodb/query_type.go:12–29  ·  view source on GitHub ↗

GetQueryType parses a MongoDB shell statement and returns its query type.

(statement string)

Source from the content-addressed store, hash-verified

10
11// GetQueryType parses a MongoDB shell statement and returns its query type.
12func GetQueryType(statement string) base.QueryType {
13 stmts, err := ParseMongoShell(statement)
14 if err != nil || len(stmts) == 0 {
15 return base.DML
16 }
17
18 node, ok := GetOmniNode(stmts[0].AST)
19 if !ok || node == nil {
20 return base.DML
21 }
22
23 a := analysis.Analyze(node)
24 if a == nil {
25 return base.DML
26 }
27
28 return omniOperationToQueryType(a)
29}
30
31// omniOperationToQueryType maps an omni StatementAnalysis to a base.QueryType.
32func omniOperationToQueryType(a *analysis.StatementAnalysis) base.QueryType {

Callers 2

GetQuerySpanFunction · 0.85
TestGetQueryTypeFunction · 0.85

Calls 3

ParseMongoShellFunction · 0.85
omniOperationToQueryTypeFunction · 0.85
GetOmniNodeFunction · 0.70

Tested by 1

TestGetQueryTypeFunction · 0.68