MCPcopy Create free account
hub / github.com/bytebase/bytebase / SplitSQL

Function SplitSQL

backend/plugin/parser/mongodb/split.go:18–36  ·  view source on GitHub ↗

SplitSQL splits the input into multiple MongoDB statements. Unlike SQL-based engines that split on semicolons, MongoDB statements can be separated by newlines without semicolons, so we use the parser to identify statement boundaries.

(statement string)

Source from the content-addressed store, hash-verified

16// separated by newlines without semicolons, so we use the parser to identify
17// statement boundaries.
18func SplitSQL(statement string) ([]base.Statement, error) {
19 stmts, err := ParseMongoShell(statement)
20 if err != nil {
21 return nil, err
22 }
23
24 if len(stmts) == 0 {
25 if len(strings.TrimSpace(statement)) == 0 {
26 return nil, nil
27 }
28 return []base.Statement{{Text: statement}}, nil
29 }
30
31 var result []base.Statement
32 for _, ps := range stmts {
33 result = append(result, ps.Statement)
34 }
35 return result, nil
36}

Callers 1

TestSplitSQLFunction · 0.70

Calls 1

ParseMongoShellFunction · 0.85

Tested by 1

TestSplitSQLFunction · 0.56