MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / ParseBytes

Function ParseBytes

pkg/sql/parser/validate.go:98–115  ·  view source on GitHub ↗

ParseBytes parses SQL from a []byte input without requiring a string conversion. This is especially useful when reading SQL from files via os.ReadFile. See issue #277.

(input []byte)

Source from the content-addressed store, hash-verified

96// This is especially useful when reading SQL from files via os.ReadFile.
97// See issue #277.
98func ParseBytes(input []byte) (*ast.AST, error) {
99 tkz := tokenizer.GetTokenizer()
100 defer tokenizer.PutTokenizer(tkz)
101
102 tokens, err := tkz.Tokenize(input)
103 if err != nil {
104 return nil, fmt.Errorf("tokenization error: %w", err)
105 }
106
107 if len(tokens) == 0 {
108 return nil, goerrors.IncompleteStatementError(models.Location{}, "")
109 }
110
111 p := GetParser()
112 defer PutParser(p)
113
114 return p.ParseFromModelTokens(tokens)
115}
116
117// ParseBytesWithTokens is like ParseBytes but also returns the preprocessed
118// token slice ([]models.TokenWithSpan) for callers that need both.

Callers 6

TestParseBytesFunction · 0.92
TestParseBytesInvalidFunction · 0.92
BenchmarkParseBytesFunction · 0.92

Calls 7

GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
GetParserFunction · 0.85
PutParserFunction · 0.85
TokenizeMethod · 0.80
ParseFromModelTokensMethod · 0.80
ErrorfMethod · 0.65

Tested by 6

TestParseBytesFunction · 0.74
TestParseBytesInvalidFunction · 0.74
BenchmarkParseBytesFunction · 0.74