classifysql

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect int

Dialect enumerates supported SQL dialects.

const (
	DialectInvalid Dialect = iota
	DialectMySQL
	DialectPostgres
	DialectSingleStore = DialectMySQL
)

type Flag

type Flag uint32

Flag is a bitmask describing statement / script properties.

const (
	IsDDL Flag = 1 << iota
	IsDML
	IsNonIdempotent
	IsMultipleStatements
	IsEasilyIdempotentFix
	IsMustNonTx // Statement must run outside a transaction (e.g. PG CREATE INDEX CONCURRENTLY)
)

Individual flag bits.

func (Flag) Names

func (f Flag) Names() []string

Names returns human-friendly names of set bits in the flag mask.

type Statement

type Statement struct {
	Flags  Flag
	Tokens sqltoken.Tokens // unstripped tokens for this statement
	// contains filtered or unexported fields
}

Statement represents one SQL statement with its original, unstripped tokens and classification flags.

func (Statement) FirstWord

func (s Statement) FirstWord() string

FirstWord returns the lower case first word

func (Statement) Strip

func (s Statement) Strip() sqltoken.Tokens

func (Statement) StripString

func (s Statement) StripString() string

StripString returns the lowercased stripped string

type Statements

type Statements []Statement

Statements is a slice of Statement.

func ClassifyTokens

func ClassifyTokens(d Dialect, majorVersion int, sqlString string) (Statements, error)

ClassifyTokens tokenizes and classifies a SQL script, returning per-statement flags and original tokens. Only error case is invalid dialect. strings.Join(ClassifyTokens().TokensList.Strings, ";") should return the original sqlString

func (Statements) CountNonEmpty

func (s Statements) CountNonEmpty() int

CountNonEmpty returns the number of real statements, excluding empty/comment-only and SET-leading statements.

func (Statements) FirstReal

func (s Statements) FirstReal() *Statement

FirstReal returns a pointer to the first real statement (non-empty, non-SET) or nil if none.

func (Statements) Regroup

func (s Statements) Regroup() []Statements

Regroup returns groups of statements that are compatible to run together in a single migration. Algorithm (single pass): Postgres: statements with IsMustNonTx must be isolated; all others can group together. MySQL: each DDL (IsDDL) isolated; consecutive/any DML grouped together. Mixed order preserved by starting a new group when incompatibility detected.

func (Statements) Summarize

func (s Statements) Summarize() Summary

Summarize builds a Summary from the classified statements.

func (Statements) TokensList

func (s Statements) TokensList() sqltoken.TokensList

type Summary

type Summary map[Flag]sqltoken.Tokens

Summary maps each flag to the first statement Tokens that exhibited it. IsMultipleStatements is synthetic.

func (Summary) Includes

func (s Summary) Includes(flags ...Flag) bool

Jump to

Keyboard shortcuts

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