formatter

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package formatter renders PostgreSQL statements as canonically-styled SQL text. It runs the input through the root sql package, walks each statement's AST, and emits a lowercase, leading-comma layout. Anything it can't render comes back as ErrUnsupportedStatement.

Index

Constants

View Source
const ErrUnsupportedStatement errs.Const = "unsupported statement"

ErrUnsupportedStatement is what you get when the formatter hits a statement kind it can't render. Match it with errors.Is, not by string.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

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

Formatter renders SQL with a fixed indentation step. It's an immutable value: the methods take a value receiver and New hands back a value, so you can copy and share a Formatter freely.

func New

func New() Formatter

New returns a Formatter that indents two spaces per step.

func (Formatter) Format

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

Format parses query and renders each statement, joining multiple ones with a blank line. A parse failure comes back unwrapped (it already carries sql.ErrParse); a statement we can't render yields ErrUnsupportedStatement.

Jump to

Keyboard shortcuts

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