Documentation
¶
Overview ¶
Package plugins defines the Transformer interface for AST middleware.
Index ¶
- Variables
- func ApplyNode(t Transformer, n nodes.Node) (nodes.Node, error)
- func ApplySelect(t Transformer, core *nodes.SelectCore) (*nodes.SelectCore, error)
- func Attributes(n nodes.Node) []*nodes.Attribute
- func ShallowAttributes(n nodes.Node) []*nodes.Attribute
- type BaseTransformer
- func (BaseTransformer) TransformDelete(s *nodes.DeleteStatement) (*nodes.DeleteStatement, error)
- func (BaseTransformer) TransformInsert(s *nodes.InsertStatement) (*nodes.InsertStatement, error)
- func (BaseTransformer) TransformSelect(c *nodes.SelectCore) (*nodes.SelectCore, error)
- func (BaseTransformer) TransformUpdate(s *nodes.UpdateStatement) (*nodes.UpdateStatement, error)
- type Scope
- type ScopedTransformer
- type StrictTransformer
- type TableRef
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var ErrUnpoliceable = errors.New("plugins: query contains SQL the transformer cannot inspect")
ErrUnpoliceable is returned when a strict transformer meets SQL it cannot inspect, such as a SqlLiteral or a StringJoin. The error never includes the raw SQL text.
Functions ¶
func ApplyNode ¶ added in v0.2.0
ApplyNode is ApplySelect for any node, such as a SetOperationNode or a DML statement. Only SelectCores are handed to t; for anything else the walker just rewrites the children.
func ApplySelect ¶ added in v0.2.0
func ApplySelect(t Transformer, core *nodes.SelectCore) (*nodes.SelectCore, error)
ApplySelect applies t to core and to every SelectCore nested inside it (subqueries, CTE bodies, joined subqueries, set-operation branches). Inner cores are transformed before the core that contains them. The input tree is never modified: each core is copied before t sees it, and every container node on the path to a changed node is copied too.
func Attributes ¶ added in v0.2.0
Attributes returns every Attribute in the tree under n, including those inside function calls and nested queries, in traversal order.
Types ¶
type BaseTransformer ¶
type BaseTransformer struct{}
BaseTransformer provides no-op defaults for all Transformer methods. Plugins embed this and override only the methods they care about.
func (BaseTransformer) TransformDelete ¶
func (BaseTransformer) TransformDelete(s *nodes.DeleteStatement) (*nodes.DeleteStatement, error)
func (BaseTransformer) TransformInsert ¶
func (BaseTransformer) TransformInsert(s *nodes.InsertStatement) (*nodes.InsertStatement, error)
func (BaseTransformer) TransformSelect ¶
func (BaseTransformer) TransformSelect(c *nodes.SelectCore) (*nodes.SelectCore, error)
func (BaseTransformer) TransformUpdate ¶
func (BaseTransformer) TransformUpdate(s *nodes.UpdateStatement) (*nodes.UpdateStatement, error)
type Scope ¶ added in v0.2.0
type Scope struct {
CTENames map[string]bool // CTEs declared on this core or any enclosing core; read-only
// Qualifiers maps each name a column may be qualified with (a table name
// or a table alias) to the underlying table name, for this core and every
// enclosing core. Inner names shadow outer ones. Derived-table aliases and
// CTE names are not tables, so they are absent. Read-only.
Qualifiers map[string]string
// contains filtered or unexported fields
}
Scope describes what is visible to the SelectCore being transformed.
CTENames and Qualifiers are read-only: the walker shares the same maps across many cores, so a transformer that wrote to them would change the scope of cores it was never shown.
func (Scope) Memo ¶ added in v0.2.0
Memo returns the value cached under key for this walk, calling fn to produce it the first time. Errors are not cached. On a zero Scope (one not created by a walk) fn is simply called every time.
func (Scope) Tables ¶ added in v0.2.0
func (s Scope) Tables(core *nodes.SelectCore) []TableRef
Tables returns the table relations referenced by core, as CollectTables does, minus any that name a CTE in scope and minus derived tables (an alias over a subquery). A derived table is policed by walking into it, so its alias must not be mistaken for a table name.
type ScopedTransformer ¶ added in v0.2.0
type ScopedTransformer interface {
TransformSelectScoped(core *nodes.SelectCore, scope Scope) (*nodes.SelectCore, error)
}
ScopedTransformer is used instead of TransformSelect when implemented.
type StrictTransformer ¶ added in v0.2.0
type StrictTransformer interface {
RefusesRawSQL() bool
}
StrictTransformer makes the walker refuse SqlLiteral nodes when RefusesRawSQL returns true.
type TableRef ¶
type TableRef struct {
Relation nodes.Node // *nodes.Table or *nodes.TableAlias
Name string // underlying table name
}
TableRef holds a reference to a table relation and its underlying name. Relation is the node used to create column references (preserving aliases), and Name is the underlying table name (for matching/filtering).
func CollectTables ¶
func CollectTables(core *nodes.SelectCore) []TableRef
CollectTables returns all table relations referenced in a SelectCore, including the FROM table and all JOIN targets. Subqueries and other non-table nodes are skipped.
type Transformer ¶
type Transformer interface {
TransformSelect(core *nodes.SelectCore) (*nodes.SelectCore, error)
TransformInsert(stmt *nodes.InsertStatement) (*nodes.InsertStatement, error)
TransformUpdate(stmt *nodes.UpdateStatement) (*nodes.UpdateStatement, error)
TransformDelete(stmt *nodes.DeleteStatement) (*nodes.DeleteStatement, error)
}
Transformer is the interface that AST transformation plugins implement. Plugins embed BaseTransformer and override only the methods they need.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
hooks
Package hooks lets package plugins lend unexported walker features to the plugins bundled with this module, without adding them to the public API.
|
Package hooks lets package plugins lend unexported walker features to the plugins bundled with this module, without adding them to the public API. |
|
Package opa provides a Transformer that enforces Open Policy Agent policies on queries by injecting policy-derived WHERE conditions.
|
Package opa provides a Transformer that enforces Open Policy Agent policies on queries by injecting policy-derived WHERE conditions. |
|
Package softdelete provides a Transformer that automatically injects "column IS NULL" conditions into SELECT queries, filtering out soft-deleted rows.
|
Package softdelete provides a Transformer that automatically injects "column IS NULL" conditions into SELECT queries, filtering out soft-deleted rows. |