formatter

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Overview

Package formatter renders PostgreSQL statements as canonically-styled SQL text. It parses the input through the root sql package, renders each statement, and then checks every rendering against the original: a statement it can't prove it reformatted faithfully — same meaning, same comments — is emitted verbatim instead. So the formatter never changes what a statement does and never drops a comment.

Rendering today is PostgreSQL's own canonical deparse with keywords lowercased, which is correct for every statement kind. The multi-line house layout (leading commas, a clause per line) is built on top of the [doc] layout engine and replaces the canonical fallback statement kind by statement kind.

Index

Constants

View Source
const ErrDeparseLeaf errs.Const = "deparse leaf"

ErrDeparseLeaf means PostgreSQL's deparser couldn't render a leaf expression. It's effectively unreachable for a node that came from a successful parse, so the verification gate, not callers, is what ever surfaces it. Match it with errors.Is.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct{}

Formatter renders SQL. It's an immutable value with nothing to configure yet, so New hands one back by value and you can copy and share it freely.

func New

func New() Formatter

New returns a Formatter.

func (Formatter) Format

func (Formatter) Format(query sql.SQL) (string, error)

Format parses query and renders each statement, separating consecutive ones with a semicolon and a blank line so the whole output re-parses as the same statements. A parse failure comes back unwrapped (it already carries sql.ErrParse). No statement kind is ever an error: one that can't be deparsed, or can't be rendered faithfully, falls back to its verbatim source.

Directories

Path Synopsis
Package doc is a small Wadler/Prettier-style document algebra: you build an immutable layout tree out of Text, Concat, Group, Indent, and the line primitives, then Render it at a target width.
Package doc is a small Wadler/Prettier-style document algebra: you build an immutable layout tree out of Text, Concat, Group, Indent, and the line primitives, then Render it at a target width.

Jump to

Keyboard shortcuts

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