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

Function parsePgStatements

backend/plugin/parser/pg/pg.go:21–50  ·  view source on GitHub ↗

parsePgStatements is the ParseStatementsFunc for PostgreSQL. Returns []ParsedStatement with both text and AST populated.

(statement string)

Source from the content-addressed store, hash-verified

19// parsePgStatements is the ParseStatementsFunc for PostgreSQL.
20// Returns []ParsedStatement with both text and AST populated.
21func parsePgStatements(statement string) ([]base.ParsedStatement, error) {
22 stmts, err := SplitSQL(statement)
23 if err != nil {
24 return nil, err
25 }
26
27 var result []base.ParsedStatement
28 for _, stmt := range stmts {
29 if stmt.Empty {
30 continue
31 }
32
33 omniStmts, omniErr := ParsePg(stmt.Text)
34 if omniErr != nil {
35 return nil, convertOmniError(omniErr, statement, stmt)
36 }
37
38 for _, os := range omniStmts {
39 result = append(result, base.ParsedStatement{
40 Statement: stmt,
41 AST: &OmniAST{
42 Node: os.AST,
43 Text: stmt.Text,
44 StartPosition: stmt.Start,
45 },
46 })
47 }
48 }
49 return result, nil
50}
51
52// convertOmniError converts an omni parser error to a base.SyntaxError with proper line:column position.
53func convertOmniError(err error, _ string, stmt base.Statement) error {

Callers

nothing calls this directly

Calls 3

ParsePgFunction · 0.85
SplitSQLFunction · 0.70
convertOmniErrorFunction · 0.70

Tested by

no test coverage detected