pgparser

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pgparser is an optional sqlguard Parser backed by a real PostgreSQL grammar (github.com/auxten/postgresql-parser, pure Go, no cgo).

It produces exact, structural answers for the false-positive-prone facts (statement kind, WHERE/LIMIT/ORDER BY/FROM presence, SELECT *, explicit INSERT columns) instead of regex guesses. SQL the grammar rejects — dynamic fragments, dialect extensions, driver placeholders it can't handle — transparently degrades to sqlguard's zero-dependency FallbackParser, so analysis never breaks the caller's query path.

Usage:

sqlguard.Register("sqlguard-pg", "pgx", middleware.WithParser(pgparser.New()))
db, _ := sql.Open("sqlguard-pg", dsn)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser implements analyzer.Parser using a PostgreSQL grammar.

func New

func New() *Parser

New returns a Postgres-dialect Parser that falls back to the zero-dependency FallbackParser on parse failure.

func (*Parser) Parse

func (p *Parser) Parse(sql string) (*analyzer.Statement, error)

Parse implements analyzer.Parser. It never returns an error: unparseable SQL yields the fallback parser's best-effort Statement (Exact=false).

Jump to

Keyboard shortcuts

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