tablefilters

package
v0.0.0-...-c558e1b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDateRange = eris.New("invalid date range")

Functions

func BuildQuery

func BuildQuery(q *bun.SelectQuery, queryStr string, opts QueryOptions) (*bun.SelectQuery, error)

func GetTotalCount

func GetTotalCount(ctx context.Context, q *bun.SelectQuery) (int, error)

GetTotalCount retrieves the total count of records for the query

Types

type ColumnType

type ColumnType string
const (
	ColumnTypeText        ColumnType = "text"
	ColumnTypeNumber      ColumnType = "number"
	ColumnTypeDate        ColumnType = "date"
	ColumnTypeBoolean     ColumnType = "boolean"
	ColumnTypeSelect      ColumnType = "select"
	ColumnTypeMultiSelect ColumnType = "multi-select"
)

type EnumField

type EnumField struct {
	TableAlias string
	Fields     []string
}

type Filter

type Filter struct {
	Field    string     `json:"field"`
	Operator Operator   `json:"operator"`
	Value    any        `json:"value"`   // Can be string, []string, number, bool, etc.
	ValueTo  any        `json:"valueTo"` // For between operations
	Type     ColumnType `json:"type"`
}

Filter represents a single filter condition

type JoinOperator

type JoinOperator string
const (
	JoinOperatorAnd JoinOperator = "and"
	JoinOperatorOr  JoinOperator = "or"
)

type Operator

type Operator string
const (
	OperatorILike      Operator = "iLike"
	OperatorNotILike   Operator = "notILike"
	OperatorEq         Operator = "eq"
	OperatorNe         Operator = "ne"
	OperatorIsEmpty    Operator = "isEmpty"
	OperatorIsNotEmpty Operator = "isNotEmpty"

	// Numeric/Date Operators
	OperatorLt        Operator = "lt"
	OperatorLte       Operator = "lte"
	OperatorGt        Operator = "gt"
	OperatorGte       Operator = "gte"
	OperatorIsBetween Operator = "isBetween"

	// Select/Multi-select Operators
	OperatorIn    Operator = "in"
	OperatorNotIn Operator = "notIn"

	// Special Operators
	OperatorIsRelativeToToday Operator = "isRelativeToToday"
)

Text Operators

type QueryOptions

type QueryOptions struct {
	TableAlias       string
	EnumFields       []EnumField
	RelationMappings []RelationMapping
}

type QueryParams

type QueryParams struct {
	Filters      []*Filter    `json:"filters"`
	JoinOperator JoinOperator `json:"joinOperator"`
}

QueryParams represents the main query parameter structure

type RelationMapping

type RelationMapping struct {
	From       string       // Source field/table name (e.g., "profile")
	To         string       // Target table alias (e.g., "worker_profiles")
	Type       RelationType // Type of relationship
	LocalKey   string       // Local key field (e.g., "id")
	ForeignKey string       // Foreign key field (e.g., "worker_id")
}

RelationMapping defines how tables are related and mapped

type RelationType

type RelationType string

RelationType defines how tables are related

const (
	RelationTypeOneToOne  RelationType = "one_to_one"
	RelationTypeOneToMany RelationType = "one_to_many"
	RelationTypeManyToOne RelationType = "many_to_one"
)

type SortOrder

type SortOrder string
const (
	SortOrderAsc  SortOrder = "asc"
	SortOrderDesc SortOrder = "desc"
)

Jump to

Keyboard shortcuts

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