Documentation
¶
Index ¶
- Constants
- Variables
- func Augment(sql string) ([]byte, error)
- func ExtractComments(sql string, scanResult *pg_query.ScanResult) []comment
- func FirstRealTokenStart(scanResult *pg_query.ScanResult, rangeStart, rangeEnd int32) int32
- func Format(sql string) (string, error)
- func FormatAugmented(data []byte) (string, error)
- func FormatParsed(parseResult *pg_query.ParseResult, scanResult *pg_query.ScanResult, ...) (string, error)
- type AugmentedAST
- type AugmentedComment
- type AugmentedStmt
- type ParsedBody
- type Printer
Constants ¶
const ( RESERV = iota MONTH YEAR DAY JULIAN TZ /* fixed-offset timezone abbreviation */ DTZ /* fixed-offset timezone abbrev, DST */ DYNTZ /* dynamic timezone abbreviation */ IGNORE_DTF AMPM HOUR MINUTE SECOND MILLISECOND MICROSECOND )
Field types for time decoding.
Can't have more of these than there are bits in an unsigned int since these are turned into bit masks during parsing and decoding.
Furthermore, the values for YEAR, MONTH, DAY, HOUR, MINUTE, SECOND must be in the range 0..14 so that the associated bitmasks can fit into the left half of an INTERVAL's typmod value. Since those bits are stored in typmods, you can't change them without initdb!
Variables ¶
var Keywords = []string{
"all",
"analyse",
"analyze",
"and",
"any",
"array",
"as",
"asc",
"asymmetric",
"both",
"case",
"cast",
"check",
"collate",
"column",
"constraint",
"create",
"current_catalog",
"current_date",
"current_role",
"current_time",
"current_timestamp",
"current_user",
"default",
"deferrable",
"desc",
"distinct",
"do",
"else",
"end",
"except",
"false",
"fetch",
"for",
"foreign",
"from",
"grant",
"group",
"having",
"in",
"initially",
"intersect",
"into",
"lateral",
"leading",
"limit",
"localtime",
"localtimestamp",
"not",
"null",
"offset",
"on",
"only",
"or",
"order",
"placing",
"primary",
"references",
"returning",
"select",
"session_user",
"some",
"symmetric",
"system_user",
"table",
"then",
"to",
"trailing",
"true",
"union",
"unique",
"user",
"using",
"variadic",
"when",
"where",
"window",
"with",
}
ReservedKeywords are PostgreSQL reserved keywords that must be quoted when used as identifiers. Sourced from PostgreSQL 17's kwlist.h (RESERVED_KEYWORD only). Non-reserved, type/func, and col-name keywords are intentionally excluded since they can be used as identifiers without quoting.
Functions ¶
func ExtractComments ¶
func ExtractComments(sql string, scanResult *pg_query.ScanResult) []comment
func FirstRealTokenStart ¶
func FirstRealTokenStart(scanResult *pg_query.ScanResult, rangeStart, rangeEnd int32) int32
firstRealTokenStart finds the byte position of the first non-comment token within the given range of the scan result. Returns rangeEnd if none found.
func FormatAugmented ¶
FormatAugmented reads augmented AST JSON and produces formatted SQL using the existing printer. The round-trip invariant is: FormatAugmented(Augment(sql)) == Format(sql)
func FormatParsed ¶
func FormatParsed(parseResult *pg_query.ParseResult, scanResult *pg_query.ScanResult, originalSQL string) (string, error)
FormatParsed formats SQL using pre-parsed results, avoiding any pgParse/pgScan calls. This is used by the WASM playground where parsing is done in JS.
Types ¶
type AugmentedAST ¶
type AugmentedAST struct {
Version int `json:"version"`
Stmts []AugmentedStmt `json:"stmts"`
}
AugmentedAST is the top-level structure for the augmented parse tree.
type AugmentedComment ¶
type AugmentedComment struct {
Text string `json:"text"`
Type string `json:"type"` // "line" or "block"
}
AugmentedComment represents a SQL comment injected into the AST.
type AugmentedStmt ¶
type AugmentedStmt struct {
Stmt json.RawMessage `json:"stmt,omitempty"`
StmtLocation int32 `json:"stmt_location,omitempty"`
StmtLen int32 `json:"stmt_len,omitempty"`
Comment *AugmentedComment `json:"comment,omitempty"`
Deparsed string `json:"deparsed,omitempty"`
}
AugmentedStmt is either a parsed statement or an inter-statement comment.
type ParsedBody ¶
type ParsedBody struct {
Language string `json:"language"`
Stmts []json.RawMessage `json:"stmts,omitempty"`
PlPgSQL json.RawMessage `json:"plpgsql,omitempty"`
Raw string `json:"raw,omitempty"`
}
ParsedBody replaces a raw function body string with its parsed form.