builder

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPostgreSQLKeyword

func IsPostgreSQLKeyword(word string) bool

PostgreSQL keyword checking (simplified implementation)

Types

type BuildOptions

type BuildOptions struct {
	FormatStyle      FormatStyle `json:"format_style"`
	IndentSize       int         `json:"indent_size"`
	MaxLineLength    int         `json:"max_line_length"`
	UseDoubleQuotes  bool        `json:"use_double_quotes"`
	NormalizeNames   bool        `json:"normalize_names"`
	PreserveComments bool        `json:"preserve_comments"`
	PostgreSQLMode   bool        `json:"postgresql_mode"`
}

BuildOptions configures SQL generation behavior

func DefaultBuildOptions

func DefaultBuildOptions() *BuildOptions

DefaultBuildOptions returns sensible defaults for PostgreSQL

type ColumnDefinition

type ColumnDefinition struct {
	Name                string `json:"name"`
	DataType            string `json:"data_type"`
	NotNull             bool   `json:"not_null"`
	Default             string `json:"default,omitempty"`
	Generated           bool   `json:"generated"`
	GeneratedExpression string `json:"generated_expression,omitempty"`
	GeneratedStored     bool   `json:"generated_stored"`
	Collation           string `json:"collation,omitempty"`
	Comment             string `json:"comment,omitempty"`
}

type ConstraintDefinition

type ConstraintDefinition struct {
	Name              string   `json:"name,omitempty"`
	Type              string   `json:"type"`
	Columns           []string `json:"columns"`
	RefTable          string   `json:"ref_table,omitempty"`
	RefColumns        []string `json:"ref_columns,omitempty"`
	OnDelete          string   `json:"on_delete,omitempty"`
	OnUpdate          string   `json:"on_update,omitempty"`
	CheckExpression   string   `json:"check_expression,omitempty"`
	Deferrable        bool     `json:"deferrable"`
	InitiallyDeferred bool     `json:"initially_deferred"`
}

type FormatStyle

type FormatStyle int

FormatStyle defines SQL formatting approaches

const (
	FormatCompact FormatStyle = iota
	FormatPretty
	FormatDense
)

type FunctionDefinition

type FunctionDefinition struct {
	Schema     string                 `json:"schema"`
	Name       string                 `json:"name"`
	Parameters []*ParameterDefinition `json:"parameters"`
	ReturnType string                 `json:"return_type"`
	Language   string                 `json:"language"`
	Body       string                 `json:"body"`
	Volatility string                 `json:"volatility"` // VOLATILE, STABLE, IMMUTABLE
	Strict     bool                   `json:"strict"`
	Security   string                 `json:"security"` // DEFINER, INVOKER
	Comment    string                 `json:"comment,omitempty"`
}

type IndexColumn

type IndexColumn struct {
	Name       string `json:"name,omitempty"`
	Expression string `json:"expression,omitempty"`
	Order      string `json:"order,omitempty"` // ASC, DESC
}

type IndexDefinition

type IndexDefinition struct {
	Schema                  string         `json:"schema"`
	Table                   string         `json:"table"`
	Name                    string         `json:"name,omitempty"`
	IfNotExists             bool           `json:"if_not_exists"`
	Unique                  bool           `json:"unique"`
	Method                  string         `json:"method"`                     // BTREE, HASH, GIN, GIST, etc.
	HadExplicitAccessMethod bool           `json:"had_explicit_access_method"` // BUG-001: Track if USING was explicit
	Columns                 []*IndexColumn `json:"columns"`
	Where                   string         `json:"where,omitempty"`
	Comment                 string         `json:"comment,omitempty"`
}

type ParameterDefinition

type ParameterDefinition struct {
	Name    string `json:"name,omitempty"`
	Type    string `json:"type"`
	Mode    string `json:"mode,omitempty"` // IN, OUT, INOUT
	Default string `json:"default,omitempty"`
}

type SQLBuilder

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

SQLBuilder provides fluent interface for PostgreSQL SQL generation

func NewSQLBuilder

func NewSQLBuilder(options *BuildOptions) *SQLBuilder

NewSQLBuilder creates a new SQL builder

func (*SQLBuilder) Comment

func (b *SQLBuilder) Comment(comment string) *SQLBuilder

Comment adds a SQL comment

func (*SQLBuilder) CreateFunction

func (b *SQLBuilder) CreateFunction(function *FunctionDefinition) *SQLBuilder

CreateFunction builds a CREATE FUNCTION statement

func (*SQLBuilder) CreateIndex

func (b *SQLBuilder) CreateIndex(index *IndexDefinition) *SQLBuilder

CreateIndex builds a CREATE INDEX statement

func (*SQLBuilder) CreateTable

func (b *SQLBuilder) CreateTable(table *TableDefinition) *SQLBuilder

CreateTable builds a CREATE TABLE statement

func (*SQLBuilder) Dedent

func (b *SQLBuilder) Dedent() *SQLBuilder

Dedent decreases indentation level

func (*SQLBuilder) Errors

func (b *SQLBuilder) Errors() []error

Errors returns any errors encountered during building

func (*SQLBuilder) FromStatement

func (b *SQLBuilder) FromStatement(stmt types.Statement) *SQLBuilder

FromStatement converts a parser statement to SQL using the builder

func (*SQLBuilder) HasErrors

func (b *SQLBuilder) HasErrors() bool

HasErrors returns true if there are any errors

func (*SQLBuilder) Indent

func (b *SQLBuilder) Indent() *SQLBuilder

Indent increases indentation level

func (*SQLBuilder) NL

func (b *SQLBuilder) NL() *SQLBuilder

NL adds a newline with proper indentation

func (*SQLBuilder) P

func (b *SQLBuilder) P(phrases ...string) *SQLBuilder

P adds phrases separated by spaces

func (*SQLBuilder) Quote

func (b *SQLBuilder) Quote(identifier string) *SQLBuilder

Quote adds properly quoted identifier

func (*SQLBuilder) QuoteQualifiedName

func (b *SQLBuilder) QuoteQualifiedName(schema, name string) *SQLBuilder

QuoteQualifiedName writes a schema-qualified name, omitting schema if empty or "public" This ensures generated SQL is clean and doesn't unnecessarily qualify names in public schema

func (*SQLBuilder) Reset

func (b *SQLBuilder) Reset() *SQLBuilder

Reset clears the builder

func (*SQLBuilder) S

func (b *SQLBuilder) S() *SQLBuilder

S adds a single space

func (*SQLBuilder) Statement

func (b *SQLBuilder) Statement(sql string) *SQLBuilder

Statement adds a complete SQL statement with automatic semicolon

func (*SQLBuilder) String

func (b *SQLBuilder) String() string

String returns the built SQL

func (*SQLBuilder) Wrap

func (b *SQLBuilder) Wrap(fn func(*SQLBuilder)) *SQLBuilder

Wrap wraps content in parentheses with proper formatting

type TableDefinition

type TableDefinition struct {
	Schema      string                  `json:"schema"`
	Name        string                  `json:"name"`
	IfNotExists bool                    `json:"if_not_exists"`
	Columns     []*ColumnDefinition     `json:"columns"`
	Constraints []*ConstraintDefinition `json:"constraints"`
	Inherits    []string                `json:"inherits,omitempty"`
	Tablespace  string                  `json:"tablespace,omitempty"`
	Comment     string                  `json:"comment,omitempty"`
}

Jump to

Keyboard shortcuts

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