parser

package
v1.191.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Omit BEGIN to allow arbitrary whitespaces between BEGIN and ATOMIC keywords.
	// This can fail if ATOMIC is used as column name because it is not a reserved
	// keyword: https://www.postgresql.org/docs/current/sql-keywords-appendix.html
	BEGIN_ATOMIC = "ATOMIC"
	END_ATOMIC   = "END"
)

Variables

View Source
var MaxScannerCapacity = 256 * 1024

MaxScannerCapacity defaults to 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

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

Types

type AtomicState

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

Opened BEGIN ATOMIC function body

func (*AtomicState) Next

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

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