sqlparse

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sqlparse implements the parse-tree-backed SQL rule types (sql/parses, sql/locking-select-order). It wraps github.com/wasilibs/go-pgquery — the real PostgreSQL 17 grammar compiled to WASM and run on wazero (pure Go, no cgo) — and hands WHOLE SQL text to the parser, which does its own statement splitting. The rules never pre-split on ';'. Nothing outside this package imports go-pgquery.

Index

Constants

This section is empty.

Variables

View Source
var ErrExtractorUnknown = errors.New("formwork: the census does not know which extractor this rule type sources through")

ErrExtractorUnknown is what CensusSites answers for a sql/* rule type that neither reassembledTypes nor fromGoTypes names.

A CENSUS LINE, NOT A SKIP, is what a caller owes this error. It is not a parse failure — there may be nothing wrong with the file at all — it is the census saying it does not know which extractor the rule sourced through and therefore has nothing true to say about what the rule declined to read. Swallowing it reports that rule's coverage as clean, which is the silence #311 half 2 is about; printing FromGo's answer instead is the false claim half 1 is about.

Functions

func AccountedForByTheCensus

func AccountedForByTheCensus(ruleType string) bool

AccountedForByTheCensus reports whether ruleType is one whose extractor CensusSites knows rather than guesses. Exported for the test that reads the live registry, which is the only thing that can say when a new type has appeared — and CensusSites now enforces the same property at runtime, so a type this returns false for is refused with ErrExtractorUnknown rather than handed FromGo's answer.

func CensusSites

func CensusSites(ruleType, path string, content []byte) ([]sqlextract.Site, bool, error)

CensusSites returns the compositions the rule TYPE ruleType declines to read in path, for the #75 escape-hatch census.

ONE FUNCTION, BECAUSE THE MAPPING FROM RULE TYPE TO EXTRACTOR IS THE THING #311 IS ABOUT. A caller that picks an extractor itself has re-derived that mapping, which is how the census came to attribute FromGo's limits to a rule that never calls it. ok is false for a type that is not a SQL rule at all, so a caller cannot silently get an answer meant for one.

The FromGo half is unfiltered, deliberately: FromGo emits a Site only for a composition it already identified as string-valued (unresolvedReason), so there is no flood to filter, and filtering would newly hide compositions the census has reported since #75.

A sql/* type in NEITHER table is refused with ErrExtractorUnknown rather than sourced by whichever extractor happens to be written last here. ok stays true — it is a SQL rule, and the caller asked the right question — so the refusal reaches the caller as the census's own gap, which it owes a line, and not as "not a SQL rule", which it owes nothing.

func UnreadableSites

func UnreadableSites(path string, content []byte) ([]sqlextract.Site, error)

UnreadableSites returns the SQL-bearing compositions in a .go file that the locking rules' extractor declined to read.

FILTERED BY looksLikeSQL, on the site's seed text. The fold tracks every string-literal-seeded local, most of which hold paths, messages and format strings; reporting each one an operator's code untracks would bury the SQL gate's real coverage gaps under the whole repo. It is the same filter statements() applies on the FromGo path (parses.go), for the same reason and with the same residual: a fragment with a leading SQL keyword and no other structural keyword is not SQL-shaped and is not reported.

A file that is not .go has no Go compositions and returns nothing. err is a Go AST parse failure only, which is the rule's to report, not the census's.

Types

type Stmt

type Stmt struct {
	Node *pg.Node
	Line int
	// Col is the seed column of the Go candidate this statement came from, 0
	// for .sql. It exists so consumers can tell two candidates seeded on ONE
	// physical line apart when deduping (#44) — line alone collapsed genuinely
	// distinct queries into a single finding.
	Col int
	// InfeasibleBaseRisk is carried from the Go candidate: this statement is
	// the `base` world of a variable with a complementary guard pair, so a
	// finding on it MAY be the disclosed #42 false positive. Carried rather
	// than re-derived — the fold is the only layer that knows the guards.
	InfeasibleBaseRisk bool
	// ClosureEscapeRisk is carried from the Go candidate too: a closure that
	// appends to this query had its NAME handed to a call — `run(add)` — so
	// this statement is the world those appends are missing from, and a finding
	// on it MAY be the disclosed #337 false positive. The string is the escape
	// as the operator will see it spelled, because the check they have to run
	// is "go read that callee" and a flag with no callee in it does not ask a
	// question anyone can answer. Empty when no closure escaped.
	ClosureEscapeRisk string
}

Stmt is one successfully-parsed SQL statement with its 1-based source line.

Jump to

Keyboard shortcuts

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