search

package
v1.1.26-test Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package search holds the column metadata and sort helpers shared by services that expose paged, sortable search endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildOrderClause

func BuildOrderClause(sortColumn, sortDirection string, columns []SearchColumn) string

BuildOrderClause constructs a SQL ORDER BY clause Validates column and direction before building Maps frontend property names to database column names

func GetDefaultSortColumn

func GetDefaultSortColumn(columns []SearchColumn) string

GetDefaultSortColumn returns the default sort column from a column definition list

func ValidateSortColumn

func ValidateSortColumn(sortColumn string, columns []SearchColumn) string

ValidateSortColumn checks if a column is valid and sortable Returns the validated column or the default if invalid

func ValidateSortDirection

func ValidateSortDirection(direction string) string

ValidateSortDirection ensures direction is either "asc" or "desc" Returns validated direction with "desc" as default

Types

type ColumnsResponse

type ColumnsResponse struct {
	Columns []SearchColumn `json:"columns"`
}

ColumnsResponse returns available columns for an entity type

type SearchColumn

type SearchColumn struct {
	Key                  string `json:"key"`                            // Column key (frontend identifier)
	Label                string `json:"label"`                          // Display name
	Sortable             bool   `json:"sortable"`                       // Can sort by this column
	DefaultSort          bool   `json:"defaultSort"`                    // Is this the default sort column
	DefaultSortDirection string `json:"defaultSortDirection,omitempty"` // "asc" or "desc" for default sort column
	DbColumn             string `json:"-"`                              // Override DB column name when different from snake_case(Key)
}

SearchColumn defines metadata for a searchable/sortable column

type SearchRequest

type SearchRequest struct {
	Query         string `json:"query"`
	Limit         int    `json:"limit,omitempty"`
	Offset        int    `json:"offset,omitempty"`
	SortColumn    string `json:"sortColumn,omitempty"`
	SortDirection string `json:"sortDirection,omitempty"` // "asc" or "desc"
}

SearchRequest is the paging and sorting shape every search request shares. Embed it in a service's request type and add the entity-specific filters alongside.

Jump to

Keyboard shortcuts

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