Documentation ¶
Overview ¶
Package clean cleans SQL queries.
This includes making identifiers lower case.
The walker in this package implements all the tree.Walker methods, even if it doesn't do anything. This is to ensure that if we need to add more cleaning / validation rules, we know that we've covered all the nodes.
For example, EnterDelete does nothing, but if we later set a limit on the amount of CTEs allowed, then we would add it there.
Index ¶
- Variables
- type StatementCleaner
- func (s *StatementCleaner) EnterAggregateFunc(node *tree.AggregateFunc) (err error)
- func (s *StatementCleaner) EnterCTE(node *tree.CTE) (err error)
- func (s *StatementCleaner) EnterCompoundOperator(node *tree.CompoundOperator) (err error)
- func (s *StatementCleaner) EnterConflictTarget(node *tree.ConflictTarget) (err error)
- func (s *StatementCleaner) EnterDateTimeFunc(node *tree.DateTimeFunction) (err error)
- func (s *StatementCleaner) EnterDelete(node *tree.Delete) (err error)
- func (s *StatementCleaner) EnterDeleteStmt(node *tree.DeleteStmt) (err error)
- func (s *StatementCleaner) EnterExpressionArithmetic(node *tree.ExpressionArithmetic) (err error)
- func (s *StatementCleaner) EnterExpressionBetween(node *tree.ExpressionBetween) (err error)
- func (s *StatementCleaner) EnterExpressionBinaryComparison(node *tree.ExpressionBinaryComparison) (err error)
- func (s *StatementCleaner) EnterExpressionBindParameter(node *tree.ExpressionBindParameter) (err error)
- func (s *StatementCleaner) EnterExpressionCase(node *tree.ExpressionCase) (err error)
- func (s *StatementCleaner) EnterExpressionCollate(node *tree.ExpressionCollate) (err error)
- func (s *StatementCleaner) EnterExpressionColumn(node *tree.ExpressionColumn) (err error)
- func (s *StatementCleaner) EnterExpressionDistinct(node *tree.ExpressionDistinct) (err error)
- func (s *StatementCleaner) EnterExpressionFunction(node *tree.ExpressionFunction) (err error)
- func (s *StatementCleaner) EnterExpressionIsNull(node *tree.ExpressionIsNull) (err error)
- func (s *StatementCleaner) EnterExpressionList(node *tree.ExpressionList) (err error)
- func (s *StatementCleaner) EnterExpressionLiteral(node *tree.ExpressionLiteral) (err error)
- func (s *StatementCleaner) EnterExpressionSelect(node *tree.ExpressionSelect) (err error)
- func (s *StatementCleaner) EnterExpressionStringCompare(node *tree.ExpressionStringCompare) (err error)
- func (s *StatementCleaner) EnterExpressionUnary(node *tree.ExpressionUnary) (err error)
- func (s *StatementCleaner) EnterFromClause(node *tree.FromClause) (err error)
- func (s *StatementCleaner) EnterGroupBy(node *tree.GroupBy) (err error)
- func (s *StatementCleaner) EnterInsert(node *tree.Insert) (err error)
- func (s *StatementCleaner) EnterInsertStmt(node *tree.InsertStmt) (err error)
- func (s *StatementCleaner) EnterJoinClause(node *tree.JoinClause) (err error)
- func (s *StatementCleaner) EnterJoinOperator(node *tree.JoinOperator) (err error)
- func (s *StatementCleaner) EnterJoinPredicate(node *tree.JoinPredicate) (err error)
- func (s *StatementCleaner) EnterLimit(node *tree.Limit) (err error)
- func (s *StatementCleaner) EnterOrderBy(node *tree.OrderBy) (err error)
- func (s *StatementCleaner) EnterOrderingTerm(node *tree.OrderingTerm) (err error)
- func (s *StatementCleaner) EnterQualifiedTableName(node *tree.QualifiedTableName) (err error)
- func (s *StatementCleaner) EnterResultColumnExpression(node *tree.ResultColumnExpression) (err error)
- func (s *StatementCleaner) EnterResultColumnStar(node *tree.ResultColumnStar) (err error)
- func (s *StatementCleaner) EnterResultColumnTable(node *tree.ResultColumnTable) (err error)
- func (s *StatementCleaner) EnterReturningClause(node *tree.ReturningClause) (err error)
- func (s *StatementCleaner) EnterReturningClauseColumn(node *tree.ReturningClauseColumn) (err error)
- func (s *StatementCleaner) EnterScalarFunc(node *tree.ScalarFunction) (err error)
- func (s *StatementCleaner) EnterSelect(node *tree.Select) (err error)
- func (s *StatementCleaner) EnterSelectCore(node *tree.SelectCore) (err error)
- func (s *StatementCleaner) EnterSelectStmt(node *tree.SelectStmt) (err error)
- func (s *StatementCleaner) EnterTableOrSubqueryJoin(node *tree.TableOrSubqueryJoin) (err error)
- func (s *StatementCleaner) EnterTableOrSubqueryList(node *tree.TableOrSubqueryList) (err error)
- func (s *StatementCleaner) EnterTableOrSubquerySelect(node *tree.TableOrSubquerySelect) (err error)
- func (s *StatementCleaner) EnterTableOrSubqueryTable(node *tree.TableOrSubqueryTable) (err error)
- func (s *StatementCleaner) EnterUpdate(node *tree.Update) (err error)
- func (s *StatementCleaner) EnterUpdateSetClause(node *tree.UpdateSetClause) (err error)
- func (s *StatementCleaner) EnterUpdateStmt(node *tree.UpdateStmt) (err error)
- func (s *StatementCleaner) EnterUpsert(node *tree.Upsert) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidIdentifier = errors.New("invalid identifier") ErrInvalidLiteral = errors.New("invalid literal") ErrInvalidBindParameter = errors.New("invalid bind parameter") ErrInvalidCollation = errors.New("invalid collation") ErrInvalidInsertType = errors.New("invalid insert type") ErrInvalidUpdateType = errors.New("invalid update type") ErrInvalidSelectType = errors.New("invalid select type") ErrInvalidJoinOperator = errors.New("invalid join operator") ErrInvalidOrderType = errors.New("invalid order type") ErrInvalidNullOrderType = errors.New("invalid null order type") ErrInvalidReturningClause = errors.New("invalid returning clause") ErrInvalidCompoundOperator = errors.New("invalid compound operator") ErrInvalidUpsertType = errors.New("invalid upsert type") ErrInvalidUnaryOperator = errors.New("invalid unary operator") ErrInvalidBinaryOperator = errors.New("invalid binary operator") ErrInvalidStringComparisonOperator = errors.New("invalid string comparison operator") ErrInvalidArithmeticOperator = errors.New("invalid arithmetic operator") )
Functions ¶
This section is empty.
Types ¶
type StatementCleaner ¶
func NewStatementCleaner ¶
func NewStatementCleaner() *StatementCleaner
TODO: the statement cleaner should also check for table / column existence
func (*StatementCleaner) EnterAggregateFunc ¶
func (s *StatementCleaner) EnterAggregateFunc(node *tree.AggregateFunc) (err error)
EnterAggregateFunc checks that the function name is a valid identifier
func (*StatementCleaner) EnterCTE ¶
func (s *StatementCleaner) EnterCTE(node *tree.CTE) (err error)
EnterCTE checks that the table name and column names are valid identifiers
func (*StatementCleaner) EnterCompoundOperator ¶
func (s *StatementCleaner) EnterCompoundOperator(node *tree.CompoundOperator) (err error)
EnterCompoundOperator validates the compound operator
func (*StatementCleaner) EnterConflictTarget ¶
func (s *StatementCleaner) EnterConflictTarget(node *tree.ConflictTarget) (err error)
EnterConflictTarget checks that the indexed column names are valid identifiers
func (*StatementCleaner) EnterDateTimeFunc ¶
func (s *StatementCleaner) EnterDateTimeFunc(node *tree.DateTimeFunction) (err error)
EnterDateTimeFunc checks that the function name is a valid identifier
func (*StatementCleaner) EnterDelete ¶
func (s *StatementCleaner) EnterDelete(node *tree.Delete) (err error)
EnterDelete does nothing
func (*StatementCleaner) EnterDeleteStmt ¶
func (s *StatementCleaner) EnterDeleteStmt(node *tree.DeleteStmt) (err error)
EnterDeleteStmt does nothing
func (*StatementCleaner) EnterExpressionArithmetic ¶
func (s *StatementCleaner) EnterExpressionArithmetic(node *tree.ExpressionArithmetic) (err error)
EnterExpressionArithmetic checks the validity of the operator
func (*StatementCleaner) EnterExpressionBetween ¶
func (s *StatementCleaner) EnterExpressionBetween(node *tree.ExpressionBetween) (err error)
EnterExpressionBetween does nothing
func (*StatementCleaner) EnterExpressionBinaryComparison ¶
func (s *StatementCleaner) EnterExpressionBinaryComparison(node *tree.ExpressionBinaryComparison) (err error)
EnterExpressionBinary checks that the operator is a valid operator
func (*StatementCleaner) EnterExpressionBindParameter ¶
func (s *StatementCleaner) EnterExpressionBindParameter(node *tree.ExpressionBindParameter) (err error)
EnterExpressionBindParameter checks that the bind parameter is a valid bind parameter
func (*StatementCleaner) EnterExpressionCase ¶
func (s *StatementCleaner) EnterExpressionCase(node *tree.ExpressionCase) (err error)
EnterExpressionCase does nothing
func (*StatementCleaner) EnterExpressionCollate ¶
func (s *StatementCleaner) EnterExpressionCollate(node *tree.ExpressionCollate) (err error)
EnterExpressionCollate checks that the collation is a valid collation
func (*StatementCleaner) EnterExpressionColumn ¶
func (s *StatementCleaner) EnterExpressionColumn(node *tree.ExpressionColumn) (err error)
EnterExpressionColumn checks that the table and column names are valid identifiers
func (*StatementCleaner) EnterExpressionDistinct ¶
func (s *StatementCleaner) EnterExpressionDistinct(node *tree.ExpressionDistinct) (err error)
EnterExpressionDistinct does nothing
func (*StatementCleaner) EnterExpressionFunction ¶
func (s *StatementCleaner) EnterExpressionFunction(node *tree.ExpressionFunction) (err error)
EnterExpressionFunction does nothing, since the function implementation is visited separately
func (*StatementCleaner) EnterExpressionIsNull ¶
func (s *StatementCleaner) EnterExpressionIsNull(node *tree.ExpressionIsNull) (err error)
EnterExpressionIsNull does nothing
func (*StatementCleaner) EnterExpressionList ¶
func (s *StatementCleaner) EnterExpressionList(node *tree.ExpressionList) (err error)
EnterExpressionList does nothing
func (*StatementCleaner) EnterExpressionLiteral ¶
func (s *StatementCleaner) EnterExpressionLiteral(node *tree.ExpressionLiteral) (err error)
EnterExpressionLiteral checks that the literal is a valid literal
func (*StatementCleaner) EnterExpressionSelect ¶
func (s *StatementCleaner) EnterExpressionSelect(node *tree.ExpressionSelect) (err error)
EnterExpressionExists checks that you can only negate EXISTS
func (*StatementCleaner) EnterExpressionStringCompare ¶
func (s *StatementCleaner) EnterExpressionStringCompare(node *tree.ExpressionStringCompare) (err error)
EnterExpressionStringCompare checks that the operator is a valid operator
func (*StatementCleaner) EnterExpressionUnary ¶
func (s *StatementCleaner) EnterExpressionUnary(node *tree.ExpressionUnary) (err error)
EnterExpressionUnary checks that the operator is a valid operator
func (*StatementCleaner) EnterFromClause ¶
func (s *StatementCleaner) EnterFromClause(node *tree.FromClause) (err error)
EnterFromClause does nothing
func (*StatementCleaner) EnterGroupBy ¶
func (s *StatementCleaner) EnterGroupBy(node *tree.GroupBy) (err error)
EnterGroupBy does nothing
func (*StatementCleaner) EnterInsert ¶
func (s *StatementCleaner) EnterInsert(node *tree.Insert) (err error)
EnterInsert does nothing
func (*StatementCleaner) EnterInsertStmt ¶
func (s *StatementCleaner) EnterInsertStmt(node *tree.InsertStmt) (err error)
EnterInsertStmt cleans the insert type, table, table alias, and columns
func (*StatementCleaner) EnterJoinClause ¶
func (s *StatementCleaner) EnterJoinClause(node *tree.JoinClause) (err error)
EnterJoinClause does nothing
func (*StatementCleaner) EnterJoinOperator ¶
func (s *StatementCleaner) EnterJoinOperator(node *tree.JoinOperator) (err error)
EnterJoinOperator validates the join operator
func (*StatementCleaner) EnterJoinPredicate ¶
func (s *StatementCleaner) EnterJoinPredicate(node *tree.JoinPredicate) (err error)
EnterJoinConstraint does nothing
func (*StatementCleaner) EnterLimit ¶
func (s *StatementCleaner) EnterLimit(node *tree.Limit) (err error)
EnterLimit does nothing
func (*StatementCleaner) EnterOrderBy ¶
func (s *StatementCleaner) EnterOrderBy(node *tree.OrderBy) (err error)
EnterOrderBy does nothing
func (*StatementCleaner) EnterOrderingTerm ¶
func (s *StatementCleaner) EnterOrderingTerm(node *tree.OrderingTerm) (err error)
EnterOrderingTerm validates the order type and null order type
func (*StatementCleaner) EnterQualifiedTableName ¶
func (s *StatementCleaner) EnterQualifiedTableName(node *tree.QualifiedTableName) (err error)
EnterQualifiedTableName checks the table name and alias and indexed by column
func (*StatementCleaner) EnterResultColumnExpression ¶
func (s *StatementCleaner) EnterResultColumnExpression(node *tree.ResultColumnExpression) (err error)
EnterResultColumnExpression checks the alias if it exists
func (*StatementCleaner) EnterResultColumnStar ¶
func (s *StatementCleaner) EnterResultColumnStar(node *tree.ResultColumnStar) (err error)
EnterResultColumnStar does nothing
func (*StatementCleaner) EnterResultColumnTable ¶
func (s *StatementCleaner) EnterResultColumnTable(node *tree.ResultColumnTable) (err error)
EnterResultColumnTable checks the table name
func (*StatementCleaner) EnterReturningClause ¶
func (s *StatementCleaner) EnterReturningClause(node *tree.ReturningClause) (err error)
EnterReturningClause does nothing
func (*StatementCleaner) EnterReturningClauseColumn ¶
func (s *StatementCleaner) EnterReturningClauseColumn(node *tree.ReturningClauseColumn) (err error)
EnterReturningClauseColumn checks that either all is selected, or that an expression is used. An alias can only be used if an expression is used.
func (*StatementCleaner) EnterScalarFunc ¶
func (s *StatementCleaner) EnterScalarFunc(node *tree.ScalarFunction) (err error)
EnterScalarFunc checks that the function name is a valid identifier and is a scalar function
func (*StatementCleaner) EnterSelect ¶
func (s *StatementCleaner) EnterSelect(node *tree.Select) (err error)
EnterSelect does nothing
func (*StatementCleaner) EnterSelectCore ¶
func (s *StatementCleaner) EnterSelectCore(node *tree.SelectCore) (err error)
EnterSelectCore validates the select type
func (*StatementCleaner) EnterSelectStmt ¶
func (s *StatementCleaner) EnterSelectStmt(node *tree.SelectStmt) (err error)
EnterSelectStmt checks that, for each SelectCore besides the last, a compound operator is provided
func (*StatementCleaner) EnterTableOrSubqueryJoin ¶
func (s *StatementCleaner) EnterTableOrSubqueryJoin(node *tree.TableOrSubqueryJoin) (err error)
EnterTableOrSubqueryJoin does nothing
func (*StatementCleaner) EnterTableOrSubqueryList ¶
func (s *StatementCleaner) EnterTableOrSubqueryList(node *tree.TableOrSubqueryList) (err error)
EnterTableOrSubqueryList does nothing
func (*StatementCleaner) EnterTableOrSubquerySelect ¶
func (s *StatementCleaner) EnterTableOrSubquerySelect(node *tree.TableOrSubquerySelect) (err error)
EnterTableOrSubquerySelect checks the alias
func (*StatementCleaner) EnterTableOrSubqueryTable ¶
func (s *StatementCleaner) EnterTableOrSubqueryTable(node *tree.TableOrSubqueryTable) (err error)
EnterTableOrSubquery checks the table name and alias
func (*StatementCleaner) EnterUpdate ¶
func (s *StatementCleaner) EnterUpdate(node *tree.Update) (err error)
EnterUpdate does nothing
func (*StatementCleaner) EnterUpdateSetClause ¶
func (s *StatementCleaner) EnterUpdateSetClause(node *tree.UpdateSetClause) (err error)
EnterUpdateSetClause checks the column names
func (*StatementCleaner) EnterUpdateStmt ¶
func (s *StatementCleaner) EnterUpdateStmt(node *tree.UpdateStmt) (err error)
EnterUpdateStmt validates the update type
func (*StatementCleaner) EnterUpsert ¶
func (s *StatementCleaner) EnterUpsert(node *tree.Upsert) (err error)
EnterUpsert validates the upsert type