mysql

package
v0.0.0-...-63e4d6e Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const InvalidPlaceholderIndex = -1

InvalidPlaceholderIndex value that represent invalid index for sql placeholders

Variables

View Source
var ErrInconsistentPlaceholder = errors.New("inconsistent placeholder usage")

ErrInconsistentPlaceholder is returned when a placeholder refers to multiple different columns.

View Source
var ErrUnsupportedQueryType = errors.New("unsupported Query type")

ErrUnsupportedQueryType represent error related unsupported Query type

View Source
var ErrUpdateLeaveDataUnchanged = errors.New("updateFunc didn't change data")

ErrUpdateLeaveDataUnchanged show that data wasn't changed in UpdateExpressionValue with updateFunc

Functions

func FilterTableExpressions

func FilterTableExpressions(statement sqlparser.Statement) (sqlparser.TableExprs, error)

FilterTableExpressions check if sqlparser.Statement contains TableExprs

func FindColumnInfo

func FindColumnInfo(fromExpr sqlparser.TableExprs, colName *sqlparser.ColName, schemaStore config.TableSchemaStore) (base.ColumnInfo, error)

FindColumnInfo get ColumnInfo from TableExprs, ColName and TableSchemaStore

func GetColumnSetting

func GetColumnSetting(column *sqlparser.ColName, tableName string, schemaStore config.TableSchemaStore) config.ColumnEncryptionSetting

GetColumnSetting get ColumnEncryptionSetting from schemaStore based on tableName and column

func GetTablesWithAliases

func GetTablesWithAliases(tables sqlparser.TableExprs) []*base.AliasedTableName

GetTablesWithAliases collect all tables from all update TableExprs which may be as subquery/table/join/etc collect only table names and ignore aliases for subqueries

func GetWhereStatements

func GetWhereStatements(stmt sqlparser.Statement) ([]*sqlparser.Where, error)

GetWhereStatements parse all Where expressions

func MapColumnsToAliases

func MapColumnsToAliases(selectQuery *sqlparser.Select, tableSchemaStore config.TableSchemaStore) ([]*base.ColumnInfo, error)

MapColumnsToAliases parse slice of ColumnInfo from sqlparser.Select and config.TableSchemaStore

func ParsePlaceholderIndex

func ParsePlaceholderIndex(placeholder *sqlparser.SQLVal) (int, error)

ParsePlaceholderIndex parse placeholder index if SQLVal is PgPlaceholder/ValArg otherwise return error and InvalidPlaceholderIndex

func ParseQuerySettings

func ParseQuerySettings(ctx context.Context, statement *sqlparser.Select, schemaStore config.TableSchemaStore) ([]*base.QueryDataItem, error)

ParseQuerySettings parse list of select query settings based on schemaStore

func ParseSearchQueryPlaceholdersSettings

func ParseSearchQueryPlaceholdersSettings(statement sqlparser.Statement, schemaStore config.TableSchemaStore) map[int]config.ColumnEncryptionSetting

ParseSearchQueryPlaceholdersSettings parse encryption settings of statement with placeholders

func UpdateExpressionValue

func UpdateExpressionValue(ctx context.Context, expr sqlparser.Expr, coder base.DBDataCoder, setting config.ColumnEncryptionSetting, updateFunc func(context.Context, []byte) ([]byte, error)) error

UpdateExpressionValue decode value from DB related string to binary format, call updateFunc, encode to DB string format and replace value in expression with new

func UpdateUnaryExpressionValue

func UpdateUnaryExpressionValue(ctx context.Context, expr *sqlparser.UnaryExpr, coder base.DBDataCoder, setting config.ColumnEncryptionSetting, updateFunc func(context.Context, []byte) ([]byte, error)) error

UpdateUnaryExpressionValue updates supported unary expression By now, supported are only `_binary` charsets, that are parsed as unary expr.

Types

type ArrayQueryObservableManager

type ArrayQueryObservableManager struct {
	// contains filtered or unexported fields
}

ArrayQueryObservableManager store all subscribed observes and call sequentially OnQuery on each observer

func NewArrayQueryObservableManager

func NewArrayQueryObservableManager(ctx context.Context) (*ArrayQueryObservableManager, error)

NewArrayQueryObservableManager create new ArrayQueryObservableManager

func (*ArrayQueryObservableManager) AddQueryObserver

func (manager *ArrayQueryObservableManager) AddQueryObserver(obs QueryObserver)

AddQueryObserver observer to array

func (*ArrayQueryObservableManager) ID

func (manager *ArrayQueryObservableManager) ID() string

ID returns name of this QueryObserver.

func (*ArrayQueryObservableManager) OnBind

func (manager *ArrayQueryObservableManager) OnBind(ctx context.Context, statement sqlparser.Statement, values []base.BoundValue) ([]base.BoundValue, bool, error)

OnBind would be called for each added observer to manager.

func (*ArrayQueryObservableManager) OnQuery

OnQuery would be called for each added observer to manager

func (*ArrayQueryObservableManager) RegisteredObserversCount

func (manager *ArrayQueryObservableManager) RegisteredObserversCount() int

RegisteredObserversCount return count of registered observers

type DBDataCoder

type DBDataCoder struct{}

DBDataCoder implement DBDataCoder for MySQL

func (*DBDataCoder) Decode

Decode decode literals from string to byte slice

func (*DBDataCoder) Encode

func (*DBDataCoder) Encode(expr sqlparser.Expr, data []byte, _ config.ColumnEncryptionSetting) ([]byte, error)

Encode data to correct literal from binary data for this expression

type OnQueryObject

type OnQueryObject interface {
	Statement() (sqlparser.Statement, error)
	Query() string
}

OnQueryObject interface for result of OnQuery call

func NewOnQueryObjectFromQuery

func NewOnQueryObjectFromQuery(query string, parser *sqlparser.Parser) OnQueryObject

NewOnQueryObjectFromQuery return OnQueryObject with query string as value

func NewOnQueryObjectFromStatement

func NewOnQueryObjectFromStatement(stmt sqlparser.Statement, parser *sqlparser.Parser) OnQueryObject

NewOnQueryObjectFromStatement return OnQueryObject with Statement as value

type QueryDataEncryptor

type QueryDataEncryptor struct {
	// contains filtered or unexported fields
}

QueryDataEncryptor parse query and encrypt raw data according to TableSchemaStore

func NewQueryEncryptor

func NewQueryEncryptor(schema config.TableSchemaStore, parser *sqlparser.Parser, dataEncryptor base.DataEncryptor) (*QueryDataEncryptor, error)

NewQueryEncryptor create QueryDataEncryptor with MySQLDBDataCoder

func (*QueryDataEncryptor) GetQueryEncryptionSettings

func (encryptor *QueryDataEncryptor) GetQueryEncryptionSettings() []*base.QueryDataItem

GetQueryEncryptionSettings returns collected in OnQuery callback encryptor settings

func (*QueryDataEncryptor) ID

func (encryptor *QueryDataEncryptor) ID() string

ID returns name of this QueryObserver.

func (*QueryDataEncryptor) OnBind

func (encryptor *QueryDataEncryptor) OnBind(ctx context.Context, statement sqlparser.Statement, values []decryptor.BoundValue) ([]decryptor.BoundValue, bool, error)

OnBind process bound values for prepared statement based on TableSchemaStore.

func (*QueryDataEncryptor) OnColumn

func (encryptor *QueryDataEncryptor) OnColumn(ctx context.Context, data []byte) (context.Context, []byte, error)

OnColumn return new encryption setting context if info exist, otherwise column data and passed context will be returned

func (*QueryDataEncryptor) OnQuery

func (encryptor *QueryDataEncryptor) OnQuery(ctx context.Context, query OnQueryObject) (OnQueryObject, bool, error)

OnQuery raw data in query according to TableSchemaStore

type QueryObservable

type QueryObservable interface {
	AddQueryObserver(QueryObserver)
	RegisteredObserversCount() int
}

QueryObservable used to handle subscribers for new incoming queries

type QueryObserver

type QueryObserver interface {
	ID() string
	// Simple queries and prepared statements during preparation stage. SQL is modifiable.
	OnQuery(ctx context.Context, data OnQueryObject) (OnQueryObject, bool, error)
	// Prepared statement parameters during execution stage. Parameter values are modifiable.
	OnBind(ctx context.Context, statement sqlparser.Statement, values []base.BoundValue) ([]base.BoundValue, bool, error)
}

QueryObserver observes database queries and is able to modify them. Methods should return "true" as their second bool result if the data has been modified.

type QueryObserverManager

type QueryObserverManager interface {
	QueryObserver
	QueryObservable
}

QueryObserverManager interface for observer aggregations

type SearchableExprItem

type SearchableExprItem struct {
	Expr    *sqlparser.ComparisonExpr
	Setting config.ColumnEncryptionSetting
}

SearchableExprItem represent the filtered value found by SearchableQueryFilter

type SearchableQueryFilter

type SearchableQueryFilter struct {
	// contains filtered or unexported fields
}

SearchableQueryFilter filter searchable expression based on SearchableQueryFilterMode

func NewSearchableQueryFilter

func NewSearchableQueryFilter(schemaStore config.TableSchemaStore, mode base.SearchableQueryFilterMode) *SearchableQueryFilter

NewSearchableQueryFilter create new SearchableQueryFilter from schemaStore and SearchableQueryFilterMode

func (*SearchableQueryFilter) ChangeSearchableOperator

func (filter *SearchableQueryFilter) ChangeSearchableOperator(expr *sqlparser.ComparisonExpr)

ChangeSearchableOperator change the operator of ComparisonExpr to EqualStr|NotEqualStr depending on expr.Operator

func (*SearchableQueryFilter) FilterSearchableComparisons

func (filter *SearchableQueryFilter) FilterSearchableComparisons(statement sqlparser.Statement) []SearchableExprItem

FilterSearchableComparisons filter search comparisons from statement

Jump to

Keyboard shortcuts

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