Documentation
¶
Index ¶
- Variables
- func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, ...) ([]base.Candidate, error)
- func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error)
- func ExtractAccessTables(statement string, option ExtractAccessTablesOption) ([]base.ColumnResource, error)
- func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, ...) (string, error)
- func GetQuerySpan(ctx context.Context, gCtx base.GetQuerySpanContext, ...) (*base.QuerySpan, error)
- func GetStatementRanges(_ context.Context, _ base.StatementRangeContext, statement string) ([]base.Range, error)
- func IsPlSQLBlock(stmt string) bool
- func IsSystemDatabase(database string) bool
- func IsSystemFunction(function string, definition string) bool
- func IsSystemSchema(schema string) bool
- func IsSystemTable(table string) bool
- func IsSystemUser(user string) bool
- func IsSystemView(view string) bool
- func NormalizePostgreSQLAnyName(ctx parser.IAny_nameContext) []string
- func NormalizePostgreSQLColid(ctx parser.IColidContext) string
- func NormalizePostgreSQLFuncName(ctx parser.IFunc_nameContext) []string
- func NormalizePostgreSQLName(ctx parser.INameContext) string
- func NormalizePostgreSQLQualifiedName(ctx parser.IQualified_nameContext) []string
- func ParsePostgreSQL(sql string) ([]*base.ParseResult, error)
- func ParsePostgreSQLPLBlock(plBlock string) (*base.ParseResult, error)
- func SplitSQL(statement string) ([]base.SingleSQL, error)
- func TransformDMLToSelect(ctx context.Context, tCtx base.TransformContext, statement string, _ string, ...) ([]base.BackupStatement, error)
- type CTETableListener
- type Completer
- type CompletionMap
- type ExtractAccessTablesOption
- type ObjectFlags
- type SetOperator
- type StatementType
- type StatementTypeWithPosition
- type TableRefListener
- func (l *TableRefListener) EnterSelect_with_parens(_ *pg.Select_with_parensContext)
- func (l *TableRefListener) EnterTable_ref(ctx *pg.Table_refContext)
- func (l *TableRefListener) ExitSelect_with_parens(_ *pg.Select_with_parensContext)
- func (l *TableRefListener) ExitTable_ref(ctx *pg.Table_refContext)
- type TableReference
- type TargetAliasListener
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Completion ¶
func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error)
Completion is the entry point of PostgreSQL code completion.
func Diagnose ¶
func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error)
func ExtractAccessTables ¶
func ExtractAccessTables(statement string, option ExtractAccessTablesOption) ([]base.ColumnResource, error)
ExtractAccessTables extracts all table/view references from a SQL statement. This is a lightweight version that doesn't perform full query span analysis.
func GenerateRestoreSQL ¶
func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error)
func GetQuerySpan ¶
func GetQuerySpan(ctx context.Context, gCtx base.GetQuerySpanContext, statement, database, schema string, _ bool) (*base.QuerySpan, error)
GetQuerySpan returns the query span for the given statement.
func GetStatementRanges ¶
func IsPlSQLBlock ¶
IsPlSQLBlock checks if the given statement is a PL/pgSQL anonymous code block (DO statement). Returns true if the statement is a DO block only, false otherwise.
func IsSystemDatabase ¶
func IsSystemFunction ¶
func IsSystemSchema ¶
func IsSystemTable ¶
func IsSystemUser ¶
func IsSystemView ¶
func NormalizePostgreSQLAnyName ¶
func NormalizePostgreSQLAnyName(ctx parser.IAny_nameContext) []string
NormalizePostgreSQLAnyName normalizes the given any name.
func NormalizePostgreSQLColid ¶
func NormalizePostgreSQLColid(ctx parser.IColidContext) string
NormalizePostgreSQLColid normalizes the given colid.
func NormalizePostgreSQLFuncName ¶
func NormalizePostgreSQLFuncName(ctx parser.IFunc_nameContext) []string
NormalizePostgreSQLFuncName normalizes the given function name.
func NormalizePostgreSQLName ¶
func NormalizePostgreSQLName(ctx parser.INameContext) string
NormalizePostgreSQLName normalizes the given name. nolint:revive
func NormalizePostgreSQLQualifiedName ¶
func NormalizePostgreSQLQualifiedName(ctx parser.IQualified_nameContext) []string
ParsePostgreSQLStatement parses the given SQL and returns the AST tree.
func ParsePostgreSQL ¶
func ParsePostgreSQL(sql string) ([]*base.ParseResult, error)
ParsePostgreSQL parses the given SQL and returns a list of ParseResult (one per statement). Use the PostgreSQL parser based on antlr4.
func ParsePostgreSQLPLBlock ¶
func ParsePostgreSQLPLBlock(plBlock string) (*base.ParseResult, error)
ParsePostgreSQLPLBlock parses the given PL/pgSQL block (BEGIN...END) and returns the ParseResult. Use the PostgreSQL parser based on antlr4, starting from pl_block rule.
func TransformDMLToSelect ¶
Types ¶
type CTETableListener ¶
type CTETableListener struct {
*pg.BasePostgreSQLParserListener
// contains filtered or unexported fields
}
func (*CTETableListener) EnterCommon_table_expr ¶
func (l *CTETableListener) EnterCommon_table_expr(ctx *pg.Common_table_exprContext)
type Completer ¶
type Completer struct {
// contains filtered or unexported fields
}
func NewStandardCompleter ¶
func NewTrickyCompleter ¶
type CompletionMap ¶
func (CompletionMap) Insert ¶
func (m CompletionMap) Insert(entry base.Candidate)
type ExtractAccessTablesOption ¶
type ExtractAccessTablesOption struct {
// DefaultDatabase is the default database name to use when table reference doesn't specify one.
DefaultDatabase string
// DefaultSchema is the default schema name to use when table reference doesn't specify one.
DefaultSchema string
// SkipMetadataValidation skips metadata lookup and validation.
// When true, returns all table references found in SQL without checking if they exist.
SkipMetadataValidation bool
// GetDatabaseMetadata is the function to get database metadata (optional, only used when SkipMetadataValidation is false).
GetDatabaseMetadata base.GetDatabaseMetadataFunc
// Ctx is the context for metadata lookup (optional, only used when SkipMetadataValidation is false).
Ctx context.Context
// InstanceID is the instance ID for metadata lookup (optional, only used when SkipMetadataValidation is false).
InstanceID string
}
ExtractAccessTablesOption configures access table extraction behavior.
type ObjectFlags ¶
type ObjectFlags int
const ( ObjectFlagsShowSchemas ObjectFlags = 1 << iota ObjectFlagsShowTables ObjectFlagsShowColumns ObjectFlagsShowFirst ObjectFlagsShowSecond )
type SetOperator ¶
type SetOperator struct {
Type string // "UNION", "EXCEPT", "INTERSECT"
IsDistinct bool // false means ALL, true means DISTINCT (or implicit distinct)
}
SetOperator represents a set operation between SELECT statements
type StatementType ¶
type StatementType int
const ( StatementTypeUnknown StatementType = iota StatementTypeUpdate StatementTypeInsert StatementTypeDelete )
type StatementTypeWithPosition ¶
type StatementTypeWithPosition struct {
Type string
// Line is the one-based line number where the statement ends.
Line int
Text string
}
StatementTypeWithPosition contains statement type and its position information.
func GetStatementTypes ¶
func GetStatementTypes(asts []base.AST) ([]StatementTypeWithPosition, error)
GetStatementTypes returns statement types with position information. The line numbers are one-based.
type TableRefListener ¶
type TableRefListener struct {
*pg.BasePostgreSQLParserListener
// contains filtered or unexported fields
}
func (*TableRefListener) EnterSelect_with_parens ¶
func (l *TableRefListener) EnterSelect_with_parens(_ *pg.Select_with_parensContext)
func (*TableRefListener) EnterTable_ref ¶
func (l *TableRefListener) EnterTable_ref(ctx *pg.Table_refContext)
func (*TableRefListener) ExitSelect_with_parens ¶
func (l *TableRefListener) ExitSelect_with_parens(_ *pg.Select_with_parensContext)
func (*TableRefListener) ExitTable_ref ¶
func (l *TableRefListener) ExitTable_ref(ctx *pg.Table_refContext)
type TableReference ¶
type TableReference struct {
Database string
Schema string
Table string
Alias string
StatementType StatementType
}
func (*TableReference) String ¶
func (t *TableReference) String() string
type TargetAliasListener ¶
type TargetAliasListener struct {
*pg.BasePostgreSQLParserListener
// contains filtered or unexported fields
}
func (*TargetAliasListener) EnterTarget_alias ¶
func (l *TargetAliasListener) EnterTarget_alias(ctx *pg.Target_aliasContext)