formatters

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type And

type And struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
	SameLine    bool
}

And formatter

func (*And) AddIndent

func (formatter *And) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*And) Format

func (formatter *And) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Case

type Case struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Case group formatter

func (*Case) AddIndent

func (formatter *Case) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Case) Format

func (formatter *Case) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Formatter

type Formatter interface {
	Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error
	AddIndent(lev int)
}

Formatter interface. Example values of Formatter would be clause group or token

type From

type From struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

From group formatter

func (*From) AddIndent

func (formatter *From) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*From) Format

func (formatter *From) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Function

type Function struct {
	Elements     []Formatter
	IndentLevel  int
	*Options     // Options used later to format element
	IsColumnArea bool
}

Function group formatter

func (*Function) AddIndent

func (formatter *Function) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Function) Format

func (formatter *Function) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Generic

type Generic struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Generic group formatter The generic group formatter can be applied if no special formatting rules are required

func (*Generic) AddIndent

func (formatter *Generic) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Generic) Format

func (formatter *Generic) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type GroupBy

type GroupBy struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

GroupBy group formatter

func (*GroupBy) AddIndent

func (formatter *GroupBy) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*GroupBy) Format

func (formatter *GroupBy) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Having

type Having struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Having group formatter

func (*Having) AddIndent

func (formatter *Having) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Having) Format

func (formatter *Having) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Insert

type Insert struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Insert group formatter

func (*Insert) AddIndent

func (formatter *Insert) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Insert) Format

func (formatter *Insert) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

func (*Insert) WriteInsert

func (formatter *Insert) WriteInsert(buf *bytes.Buffer, token, previousToken Token, indent int)

type Join

type Join struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Join group formatter

func (*Join) AddIndent

func (formatter *Join) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Join) Format

func (formatter *Join) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Limit

type Limit struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Limit group formatter Limit such as LIMIT, OFFSET, FETCH FIRST

func (*Limit) AddIndent

func (formatter *Limit) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Limit) Format

func (formatter *Limit) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Lock

type Lock struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Lock group formatter

func (*Lock) AddIndent

func (formatter *Lock) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Lock) Format

func (formatter *Lock) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Options

type Options struct {
	Padding    string        // Character sequence added as left padding on all lines, e.g. "" (none)
	Indent     string        // Character sequence used left indentation on indented clauses, e.g. "    " (4 spaces)
	Newline    string        // Character sequence used as line feeds, e.g. "\n" (newline character)
	Whitespace string        // Character sequence used as whitespace in SQL string, e.g. " " (single space)
	Dialect    lexer.Dialect // SQL dialect for formatting rules
}

Options to define output format of Formatters

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns a default options set for Formatters. Also used in unit tests.

type Or

type Or struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
	SameLine    bool
}

Or formatter

func (*Or) AddIndent

func (formatter *Or) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Or) Format

func (formatter *Or) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type OrderBy

type OrderBy struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

OrderBy group formatter

func (*OrderBy) AddIndent

func (formatter *OrderBy) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*OrderBy) Format

func (formatter *OrderBy) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Parenthesis

type Parenthesis struct {
	Elements         []Formatter
	IndentLevel      int
	*Options         // Options used later to format element
	IsColumnArea     bool
	PositionInParent int
}

Parenthesis group formatter

func (*Parenthesis) AddIndent

func (formatter *Parenthesis) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Parenthesis) Format

func (formatter *Parenthesis) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Returning

type Returning struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Returning group formatter

func (*Returning) AddIndent

func (formatter *Returning) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Returning) Format

func (formatter *Returning) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Select

type Select struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Select group formatter

func (*Select) AddIndent

func (formatter *Select) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Select) Format

func (formatter *Select) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Set

type Set struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Set group formatter

func (*Set) AddIndent

func (formatter *Set) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Set) Format

func (formatter *Set) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Subquery

type Subquery struct {
	Elements     []Formatter
	IndentLevel  int
	*Options     // Options used later to format element
	IsColumnArea bool
}

Subquery formatters

func (*Subquery) AddIndent

func (formatter *Subquery) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Subquery) Format

func (formatter *Subquery) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type TieGroup

type TieGroup struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

TieGroup group formatter TieGroup such as UNION, EXCEPT, INTERSECT

func (*TieGroup) AddIndent

func (formatter *TieGroup) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*TieGroup) Format

func (formatter *TieGroup) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Token

type Token struct {
	lexer.Token
	*Options
}

Token wrapping lexer Token but extended with Options struct

func (Token) AddIndent

func (formatter Token) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (Token) ContinueLine

func (formatter Token) ContinueLine() bool

ContinueLine should be called on the last parent token to see, if a token should continue in the same line

func (Token) ContinueNewline

func (formatter Token) ContinueNewline() bool

ContinueNewline returns true if a token should be moved to a new line

func (Token) Format

func (formatter Token) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

func (Token) IsComparator

func (formatter Token) IsComparator() bool

IsComparator returns true if token is a comparator

func (Token) IsJoinStart

func (formatter Token) IsJoinStart() bool

IsJoinStart determines if token type is included in TokenTypesOfJoinMaker

func (Token) IsLimitClauseStart

func (formatter Token) IsLimitClauseStart() bool

IsLimitClauseStart determines token type is included in TokenTypesOfLimitClause

func (Token) IsTieClauseStart

func (formatter Token) IsTieClauseStart() bool

IsTieClauseStart determines if token type is included in TokenTypesOfTieClause

type Type

type Type struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Type group formatter

func (*Type) AddIndent

func (formatter *Type) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Type) Format

func (formatter *Type) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type Values

type Values struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Values group formatter

func (*Values) AddIndent

func (formatter *Values) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Values) Format

func (formatter *Values) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

func (*Values) WriteValues

func (formatter *Values) WriteValues(buf *bytes.Buffer, token Token, indent int)

type Where

type Where struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

Where group formatter

func (*Where) AddIndent

func (formatter *Where) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*Where) Format

func (formatter *Where) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

type With

type With struct {
	Elements    []Formatter
	IndentLevel int
	*Options    // Options used later to format element
}

With group formatter

func (*With) AddIndent

func (formatter *With) AddIndent(lev int)

AddIndent increments indentation level by the given amount

func (*With) Format

func (formatter *With) Format(buf *bytes.Buffer, parent []Formatter, parentIdx int) error

Format component accordingly with necessary indents, newlines,...

Jump to

Keyboard shortcuts

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