query

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package query reads, splits, and classifies SQL input.

Index

Constants

This section is empty.

Variables

View Source
var ErrMultipleInputs = errors.New("specify only one of --sql, --file, or stdin")

ErrMultipleInputs is returned when SQL is supplied through more than one supported source at the same time.

Functions

func AnalysisText

func AnalysisText(sql string) string

AnalysisText returns SQL with comments and literals scrubbed while preserving line breaks, making keyword-based safety checks less prone to false matches.

func CommentlessText

func CommentlessText(sql string) string

CommentlessText returns SQL with comments scrubbed but literal contents kept, which supports checks that need string patterns such as LIKE wildcards.

func HasToken

func HasToken(tokens []string, token string) bool

func HasTokenSequence

func HasTokenSequence(tokens []string, sequence ...string) bool

func Mutating

func Mutating(sql string) bool

Mutating reports whether any statement appears to change database state. Read-like statement prefixes are allowed; everything else is treated conservatively as a mutation.

func Read

func Read(src Source) (string, error)

Read loads SQL from Source, rejecting ambiguous input combinations so callers do not accidentally execute different text than intended.

func Statements

func Statements(sql string) []string

Statements splits SQL into executable statements without line metadata.

func Tokens

func Tokens(sql string) []string

Tokens returns lowercase SQL tokens after comments and literal contents have been scrubbed. It is intentionally conservative, but avoids matching keywords hidden inside strings, comments, or identifier substrings.

Types

type Danger

type Danger struct {
	Type    string
	Message string
}

Danger describes a SQL pattern that is unsafe enough to block in readonly or guarded execution modes.

func Dangerous

func Dangerous(sql string) (Danger, bool)

Dangerous returns the first destructive SQL statement detected in sql.

type Source

type Source struct {
	SQL  string
	File string
	In   io.Reader
}

Source describes the mutually exclusive places where SQL can be read from.

type Statement

type Statement struct {
	SQL  string
	Line int
}

Statement contains one SQL statement and the one-based line where it starts.

func StatementsWithLine

func StatementsWithLine(sql string) []Statement

StatementsWithLine splits SQL on semicolons that are outside quoted strings and comments, preserving the starting line for diagnostics.

Jump to

Keyboard shortcuts

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