Documentation
¶
Index ¶
- func IsPostgreSQLKeyword(word string) bool
- type BuildOptions
- type ColumnDefinition
- type ConstraintDefinition
- type FormatStyle
- type FunctionDefinition
- type IndexColumn
- type IndexDefinition
- type ParameterDefinition
- type SQLBuilder
- func (b *SQLBuilder) Comment(comment string) *SQLBuilder
- func (b *SQLBuilder) CreateFunction(function *FunctionDefinition) *SQLBuilder
- func (b *SQLBuilder) CreateIndex(index *IndexDefinition) *SQLBuilder
- func (b *SQLBuilder) CreateTable(table *TableDefinition) *SQLBuilder
- func (b *SQLBuilder) Dedent() *SQLBuilder
- func (b *SQLBuilder) Errors() []error
- func (b *SQLBuilder) FromStatement(stmt types.Statement) *SQLBuilder
- func (b *SQLBuilder) HasErrors() bool
- func (b *SQLBuilder) Indent() *SQLBuilder
- func (b *SQLBuilder) NL() *SQLBuilder
- func (b *SQLBuilder) P(phrases ...string) *SQLBuilder
- func (b *SQLBuilder) Quote(identifier string) *SQLBuilder
- func (b *SQLBuilder) QuoteQualifiedName(schema, name string) *SQLBuilder
- func (b *SQLBuilder) Reset() *SQLBuilder
- func (b *SQLBuilder) S() *SQLBuilder
- func (b *SQLBuilder) Statement(sql string) *SQLBuilder
- func (b *SQLBuilder) String() string
- func (b *SQLBuilder) Wrap(fn func(*SQLBuilder)) *SQLBuilder
- type TableDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPostgreSQLKeyword ¶
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 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 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) Statement ¶
func (b *SQLBuilder) Statement(sql string) *SQLBuilder
Statement adds a complete SQL statement with automatic semicolon
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"`
}