prime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 6 Imported by: 0

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

func (f *Filter) RegisterColumnValidator(validator column.Validator)

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

func (f *Filter) RegisterFilter(matchMode filter.MatchMode, filter filter.Filter)

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

func (f *Filter) Sql(specs Specs) (vals []any, condition string, err error)

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

func (f *Filter) ValidateColumns(specs Specs) error

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.

type Specs

type Specs map[string][]filter.Spec

Jump to

Keyboard shortcuts

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