sqlanalyzer

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptRecoverer added in v0.7.0

type AcceptRecoverer struct {
	tree.Accepter
}

AcceptRecoverer is a wrapper around a statement that implements the accepter interface it catches panics and returns them as errors

func NewAcceptRecoverer added in v0.7.0

func NewAcceptRecoverer(a tree.Accepter) *AcceptRecoverer

func (*AcceptRecoverer) Accept added in v0.7.0

func (a *AcceptRecoverer) Accept(walker tree.Walker) (err error)

type AnalyzedStatement

type AnalyzedStatement struct {
	// Statement is the rewritten SQL statement, with the correct rules applied
	Statement string
	// Mutative indicates if the statement mutates state.
	// If true, then the statement cannot run in a read-only transaction.
	Mutative bool
	// HasTableRefs indicates if the statement included tables IFF the
	// NamedParametersVisitor was run on the AST after parsing. These tables
	// would have had a schema prefixed by the walker. This can indicate if the
	// statement alone is not likely to provide type (OID) information by
	// preparing the statement with the database backend.
	HasTableRefs bool
	// ParameterOrder is a list of the parameters in the order they appear in the statement.
	// This is set if the ReplaceNamedParameters flag is set.
	// For example, if the statement is "SELECT * FROM table WHERE id = $id AND name = @caller",
	// then the parameter order would be ["$id", "@caller"]
	ParameterOrder []string
}

AnalyzedStatement is a statement that has been analyzed by the analyzer As we progressively add more types of analysis (e.g. query pricing), we will add more fields to this struct

func ApplyRules

func ApplyRules(stmt string, flags VerifyFlag, tables []*common.Table, pgSchemaName string) (*AnalyzedStatement, error)

ApplyRules analyzes the given statement and returns the transformed statement. It parses it, and then traverses the AST with the given flags. It will alter the statement to make it conform to the given flags, or return an error if it cannot. All tables will target the pgSchemaName schema.

type VerifyFlag

type VerifyFlag uint8
const (
	// NoCartesianProduct prevents cartesian products from being generated
	NoCartesianProduct VerifyFlag = 1 << iota
	// GuaranteedOrder provides a guarantee of deterministic ordering of the results (even if it is not explicitly specified in the query)
	GuaranteedOrder
	// ReplaceNamedParameters replaces named parameters with numbered parameters
	ReplaceNamedParameters
)

Directories

Path Synopsis
Package attributes analyzes a returned relations attributes, maintaining order.
Package attributes analyzes a returned relations attributes, maintaining order.
Package clean cleans SQL queries.
Package clean cleans SQL queries.

Jump to

Keyboard shortcuts

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