parsers

package
v0.0.0-...-b8497f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package parsers contains the concrete implementations of the Parser interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AntlrParser

type AntlrParser struct{}

AntlrParser is a SQL parser that uses ANTLR to build a parse tree.

func NewAntlrParser

func NewAntlrParser() *AntlrParser

NewAntlrParser creates a new AntlrParser.

func (*AntlrParser) ListTables

func (p *AntlrParser) ListTables(sql string) ([]string, error)

ListTables extracts table names from a SQL query using the ANTLR parser.

type BaseParser

type BaseParser struct{}

func (*BaseParser) ListTables

func (bp *BaseParser) ListTables(ast string) (tables []string)

type ParseResult

type ParseResult struct {
	Tables        []string
	QueryTemplate string
	Params        []string
}

type RegexParser

type RegexParser struct{}

RegexParser is a SQL parser that uses regular expressions to extract information from queries.

func NewRegexParser

func NewRegexParser() *RegexParser

NewRegexParser creates a new RegexParser.

func (*RegexParser) ListTables

func (p *RegexParser) ListTables(sql string) ([]string, error)

ListTables extracts table names from a SQL query using a regular expression. It finds all matches for tables in `FROM` and `JOIN` clauses and returns a deduplicated slice of table names.

type SQLParser

type SQLParser interface {
	Parse(query string) (*ParseResult, error)
	ListTables(ast string) []string
}

type StreamingTraceParser

type StreamingTraceParser struct {
	BufferSize int
}

StreamingTraceParser is responsible for parsing trace files in a streaming fashion.

func NewStreamingTraceParser

func NewStreamingTraceParser(bufferSize int) *StreamingTraceParser

NewStreamingTraceParser creates a new StreamingTraceParser with the given buffer size.

func (*StreamingTraceParser) ListTables

func (p *StreamingTraceParser) ListTables(sql string) ([]string, error)

ListTables extracts table names from a SQL query. It implements the services.Parser interface.

func (*StreamingTraceParser) Parse

func (p *StreamingTraceParser) Parse(reader io.Reader, callback func(models.SQLTrace) error) error

Parse reads the provided reader line by line, unmarshals each line into a SQLTrace object, and calls the callback function with the parsed trace.

type TableListener

type TableListener struct {
	*mysql.BaseMySqlParserListener
	TableNames []string
}

TableListener is an ANTLR listener that extracts table names from a SQL query.

func NewTableListener

func NewTableListener() *TableListener

NewTableListener creates a new TableListener.

func (*TableListener) EnterTable_reference

func (l *TableListener) EnterTable_reference(ctx *mysql.Table_referenceContext)

EnterTable_reference is called when the listener enters a `table_reference` node in the parse tree. It extracts the table name from the node and adds it to the list of table names.

Directories

Path Synopsis
antlr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL