parse

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lex

func Lex(query string, options ...LexOption) string

Lex through a given query, optionally substituting some values in the string

func SplitStatements added in v1.3.5

func SplitStatements(query string) []string

SplitStatements breaks a SQL string into individual statements separated by semicolons that are not contained within literals, comments, or procedural blocks.

Types

type LexOption

type LexOption func(*Lexer)

LexOption is a function that sets a preference on the lexer

func LexOptions

func LexOptions(opts ...LexOption) LexOption

LexOptions converts an aritrary number of options into one function for easier handling

func WithNamedCallback

func WithNamedCallback(cb OnNamedParam) LexOption

WithNamedCallback sets the optional named parameter callback

func WithPositionalSubstitution

func WithPositionalSubstitution(cb SubstitutePosParam) LexOption

WithPositionalSubstitution sets the optional positional substitution callback

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer loosely breaks a SQL query down into chunks that the Vertica package cares about, offering opportunities for substitution.

type OnNamedParam

type OnNamedParam func(name string)

OnNamedParam is called when a value such as @queryParam is encountered. This can be used to associate a placeholder in the SQL to an index. The placeholders are encountered in the order they appear in the string.

type StatementNesting added in v1.4.0

type StatementNesting struct {
	// contains filtered or unexported fields
}

StatementNesting tracks procedural blocks while splitting SQL. An IF that is not the first token of a statement and is followed by [NOT] EXISTS is a DDL existence modifier (for example DROP TABLE IF EXISTS or ADD COLUMN IF NOT EXISTS), not the start of a procedural IF block. Its zero value is ready for use.

func (*StatementNesting) Consume added in v1.4.0

func (n *StatementNesting) Consume(token, query string, nextTokenStart int)

Consume processes an uppercase token and its position in the SQL text.

func (*StatementNesting) Depth added in v1.4.0

func (n *StatementNesting) Depth() int

Depth returns the number of open procedural blocks.

func (*StatementNesting) EndStatement added in v1.4.0

func (n *StatementNesting) EndStatement()

EndStatement starts a new statement within the current procedural block.

type SubstitutePosParam

type SubstitutePosParam func() string

SubstitutePosParam is called by the lexer when a '?' rune is encountered outside a string. The return value is substituted for the placeholder. This can be used to emulate server side binding but should be done with extreme caution due to the risk of SQL injection.

Jump to

Keyboard shortcuts

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