parser

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxScannerCapacity = 256 * 1024

Default max capacity is 64 * 1024 which is not enough for certain lines containing e.g. geographical data. 256K ought to be enough for anybody...

Functions

func Split

func Split(sql io.Reader, transform ...func(string) string) (stats []string, err error)

Use bufio.Scanner to split a PostgreSQL string into multiple statements.

The core problem is to figure out whether the current ; separator is inside an escaped string literal. PostgreSQL has multiple ways of opening a string literal, $$, ', --, /*, etc. We use a FSM to guarantee these states are entered exclusively. If not in one of the above escape states, the next ; token can be parsed as statement separator.

Each statement is split as it is, without removing comments or white spaces.

func SplitAndTrim added in v1.17.4

func SplitAndTrim(sql io.Reader) (stats []string, err error)

Types

type BlockState

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

Opened a block comment

func (*BlockState) Next

func (s *BlockState) Next(r rune, data []byte) State

type CommentState

type CommentState struct{}

Opened a line comment

func (*CommentState) Next

func (s *CommentState) Next(r rune, data []byte) State

type DollarState

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

Opened a dollar quote, no characters are ever esacped.

func (*DollarState) Next

func (s *DollarState) Next(r rune, data []byte) State

type EscapeState

type EscapeState struct{}

Opened a \ escape

func (*EscapeState) Next

func (s *EscapeState) Next(r rune, data []byte) State

type QuoteState

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

Opened a single quote ' or double quote "

func (*QuoteState) Next

func (s *QuoteState) Next(r rune, data []byte) State

type ReadyState

type ReadyState struct{}

Initial state: ready to parse next token

func (*ReadyState) Next

func (s *ReadyState) Next(r rune, data []byte) State

type State

type State interface {
	// Return nil to emit token
	Next(r rune, data []byte) State
}

type TagState

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

Opened a tag, ie. $tag$

func (*TagState) Next

func (s *TagState) Next(r rune, data []byte) State

Jump to

Keyboard shortcuts

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