sqlpolicy

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package sqlpolicy provides a small, dialect-neutral SQL lexical boundary. It recognizes statement separators and unquoted ASCII words without trying to parse SQL grammar. Callers remain responsible for an explicit allowlist.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSQL = errors.New("SQL text is invalid")

ErrInvalidSQL reports input that cannot be safely classified as SQL text.

Functions

func HasTemporarySchemaReference

func HasTemporarySchemaReference(tokens []Token) bool

HasTemporarySchemaReference reports whether tokens contain a quoted or unquoted temp schema qualifier.

func ValidateMigrationScript

func ValidateMigrationScript(text string, maxBytes int) error

ValidateMigrationScript accepts a bounded sequence of durable DDL and DML statements. Transaction-control statements, temporary schema, REPLACE/WITH extensions, and executable ROLLBACK policy are outside this strict profile. CREATE TRIGGER bodies are recognized so their internal semicolons and BEGIN/END delimiters are not mistaken for top-level transaction control.

Types

type Token

type Token struct {
	Word       string
	Identifier string
	String     string
	Symbol     string
	Separator  bool
	Other      bool
}

Token is one unquoted ASCII word, quoted identifier, quoted string, punctuation symbol, semicolon statement separator, or other executable SQL content. Whitespace and comments are skipped. String is retained only so a caller can reject dialects that permit quoted schema names; it remains Other.

func Tokenize

func Tokenize(text string, maxBytes int) ([]Token, error)

Tokenize returns the executable words and statement separators in text. maxBytes must be positive. NUL, invalid UTF-8, oversized input, and unterminated quoted values or block comments fail closed.

Jump to

Keyboard shortcuts

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