Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter manages a collection of SQL filters and their associated placeholders. It stores filters by their match modes and provides methods for creating new filters and registering additional filters. The placeholder used in SQL conditions is represented by the Placeholder interface, allowing for different placeholder styles.
func New ¶
func New(placeholder placeholder.Placeholder) *Filter
New creates a new Filter instance with the specified placeholder. It initializes the filters map as an empty map and sets up column validators as an empty slice. Parameters:
placeholder: An implementation of the Placeholder interface for SQL conditions.
Returns:
A pointer to a newly created Filter instance.
func NewWithFilters ¶
func NewWithFilters(placeholder placeholder.Placeholder, filters map[filter.MatchMode]filter.Filter) *Filter
NewWithFilters creates a new Filter instance with the specified placeholder and initializes it with a map of filters. Parameters:
placeholder: An implementation of the Placeholder interface for SQL conditions. filters: A map of filter.MatchMode to filter.Filter to initialize the Filter with.
Returns:
A pointer to a newly created Filter instance with the specified filters.
func NewWithFiltersAndValidators ¶
func NewWithFiltersAndValidators(placeholder placeholder.Placeholder, filters map[filter.MatchMode]filter.Filter, validators column.Validators) *Filter
NewWithFiltersAndValidators creates a new Filter instance with the specified placeholder, filters, and column validators. Parameters:
placeholder: An implementation of the Placeholder interface for SQL conditions. filters: A map of filter.MatchMode to filter.Filter to initialize the Filter with. validators: A slice of column validators to be used for validating column values.
Returns:
A pointer to a newly created Filter instance with the specified filters and validators.
func (*Filter) RegisterColumnValidator ¶
RegisterColumnValidator adds a new column validator to the Filter's list of validators. Parameters:
validator: A Validator to be applied to a column.
func (*Filter) RegisterFilter ¶
RegisterFilter adds a new filter for a specific match mode to the Filter. Parameters:
matchMode: The match mode for which to register the filter. filter: The filter to be registered for the specified match mode.
func (*Filter) Sql ¶
Sql generates an SQL condition string and associated values based on the provided Specs. It constructs a WHERE clause and prepares the corresponding values for parameterized queries.
Parameters:
specs: The Specs object that provides the specifications for generating the SQL conditions. It is iterated to extract match modes and other necessary details.
Returns:
vals: A slice of values that correspond to the placeholders in the SQL condition. condition: The SQL WHERE clause condition string composed of the conditions derived from specs. err: An error, if any, encountered during the process.
func (*Filter) ValidateColumns ¶
ValidateColumns checks if the columns specified in the Specs are valid according to the registered column validators. Parameters:
specs: The Specs object that provides the specifications for generating the SQL conditions.
Returns:
error: Returns an error if any of the columns are invalid or if a validation error occurs. Returns nil if all columns are valid.