parser

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedRoutine = errors.New("unsupported routine")

ErrUnsupportedRoutine marks a CREATE FUNCTION / PROCEDURE statement that pistachio reads but does not manage. The parser turns it into the same "ignored unsupported statement" warning any other unhandled statement gets, and the catalog skips the row rather than failing the whole read, so both sides of the diff leave the same routines out. Never fail a parse over one: a routine the desired schema declares is read whether or not --manage-routine is set, so an error here would reach someone who never asked for routines at all.

Functions

func FormatExecuteStmt added in v0.22.0

func FormatExecuteStmt(es *ExecuteStmt) string

FormatExecuteStmt formats an ExecuteStmt as SQL with the directive comment.

func FormatExecuteStmtWithNote added in v1.23.0

func FormatExecuteStmtWithNote(es *ExecuteStmt, note string) string

FormatExecuteStmtWithNote formats an ExecuteStmt with an extra comment line between the directive and the SQL. note is used by plan to record that the check SQL could not be evaluated, so the statement is shown without a verdict. Newlines in note are folded to keep the comment on one line.

func ParseRoutineDef added in v1.30.0

func ParseRoutineDef(sql, defaultSchema string) (*model.Routine, error)

ParseRoutineDef builds a Routine from a single CREATE FUNCTION or CREATE PROCEDURE statement. The catalog reads pg_get_functiondef and calls this, so both sides of the diff go through one code path and render through one model.Routine.SQL.

Types

type ExecuteStmt added in v0.22.0

type ExecuteStmt struct {
	SQL      string `json:"sql"`       // The SQL statement to execute
	CheckSQL string `json:"check_sql"` // Optional condition check SQL (empty = always execute)
	// First reports whether the statement came from -- pista:execute-first,
	// which runs before the managed DDL instead of after it. Its check SQL is
	// therefore evaluated against the pre-change schema.
	First bool `json:"first"`
}

ExecuteStmt represents an arbitrary SQL statement marked with -- pista:execute or -- pista:execute-first.

type ParseResult

type ParseResult struct {
	Tables         *orderedmap.Map[string, *model.Table]         `json:"tables"`
	Views          *orderedmap.Map[string, *model.View]          `json:"views"`
	Enums          *orderedmap.Map[string, *model.Enum]          `json:"enums"`
	Domains        *orderedmap.Map[string, *model.Domain]        `json:"domains"`
	CompositeTypes *orderedmap.Map[string, *model.CompositeType] `json:"composite_types"`
	Sequences      *orderedmap.Map[string, *model.Sequence]      `json:"sequences"`
	Routines       *orderedmap.Map[string, *model.Routine]       `json:"routines"`
	ExecuteStmts   []*ExecuteStmt                                `json:"execute_stmts"`
}

func ParseSQLFilesWithSchema added in v0.4.0

func ParseSQLFilesWithSchema(paths []string, defaultSchema string) (*ParseResult, error)

func ParseSQLSourcesWithSchema added in v1.55.0

func ParseSQLSourcesWithSchema(sources []Source, defaultSchema string) (*ParseResult, error)

ParseSQLSourcesWithSchema parses SQL that is already in memory, the way ParseSQLFilesWithSchema parses the files it reads. A caller that did not read a file uses it to keep the file name in an error and a warning.

type Source added in v1.55.0

type Source struct {
	Name string
	SQL  string
}

Source is one piece of desired-schema SQL and the name a message calls it by. A file's name is its path; SQL read out of a git repository carries the revision as well, so an error says which version of the file it is in.

Jump to

Keyboard shortcuts

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