filter

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: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Column   string
	Filter   Filter
	Operator string
}

type Filter

type Filter interface {
	// Apply creates an SQL condition string for the WHERE clause.
	// Parameters:
	//   column: The name of the SQL column to filter.
	//   totalArguments: The total number of arguments in the query.
	//   currentIndex: The index of the current argument.
	//   placeholder: The placeholder interface for generating the placeholder string (e.g., "?").
	// Returns:
	//   A string representing the SQL condition to append to the WHERE clause.
	Apply(column string, totalArguments int, currentIndex int, placeholder placeholder.Placeholder) string

	// EnrichValue modifies the value pointed to by `*any` and returns an error if the modification fails.
	// This method is used to preprocess or adjust the value before using it in the query.
	// For example, in a StartsWithFilter, you might append '%' to the value to use it with a LIKE condition.
	// Parameters:
	//   value: A pointer to the value to be modified. The value is adjusted in place.
	// Returns:
	//   An error if the value could not be modified; otherwise, nil.
	EnrichValue(value *any) error
}

Filter provides methods for constructing and modifying SQL filter conditions.

type MatchMode

type MatchMode string
const (
	EQUALS              MatchMode = "equals"
	NOT_EQUALS          MatchMode = "notEquals"
	CONTAINS            MatchMode = "contains"
	NOT_CONTAINS        MatchMode = "notContains"
	STARTS_WITH         MatchMode = "startsWith"
	ENDS_WITH           MatchMode = "endsWith"
	LESS_THAN           MatchMode = "lt"
	LESS_THAN_EQUALS    MatchMode = "lte"
	GREATER_THAN        MatchMode = "gt"
	GREATER_THAN_EQUALS MatchMode = "gte"
	DATE_BEFORE         MatchMode = "dateBefore"
	DATE_AFTER          MatchMode = "dateAfter"
	DATE_IS             MatchMode = "dateIs"
	DATE_IS_NOT         MatchMode = "dateIsNot"
	IN                  MatchMode = "in"
	BETWEEN             MatchMode = "between"
)

type Spec

type Spec struct {
	Value     any       `json:"value"`
	MatchMode MatchMode `json:"matchMode"`
	Operator  string    `json:"operator,omitempty"`
}

Jump to

Keyboard shortcuts

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