db_utils

package
v0.1.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDBFieldMap

func GetDBFieldMap(input any) map[string]string

Types

type ConditionsMap

type ConditionsMap map[string]*QueryCondition

func GenerateConditionsFor

func GenerateConditionsFor[T any]() (ConditionsMap, []string)

func GenerateConditionsFromEntity

func GenerateConditionsFromEntity(entity interface{}) (ConditionsMap, []string)

func NewConditionsMap

func NewConditionsMap() ConditionsMap

func (ConditionsMap) AddCondition

func (cm ConditionsMap) AddCondition(key string, condition *QueryCondition) ConditionsMap

func (ConditionsMap) Remove

func (cm ConditionsMap) Remove(key string) (*QueryCondition, bool)

func (ConditionsMap) Update

func (cm ConditionsMap) Update(key string, operator sql_enum.QueryOperator, value ...interface{}) ConditionsMap

func (ConditionsMap) UpdateRequired

func (cm ConditionsMap) UpdateRequired(key string, required bool) (ConditionsMap, bool)

func (ConditionsMap) UpdateRequiredWithPanic

func (cm ConditionsMap) UpdateRequiredWithPanic(key string, required bool) ConditionsMap

type PaginatedResult

type PaginatedResult[T any] struct {
	Items      []*T  `json:"items"`
	Total      int64 `json:"total"`
	Page       int   `json:"page"`
	Size       int   `json:"size"`
	TotalPages int   `json:"totalPages"`
}

type Pagination

type Pagination struct {
	Page   int
	Limit  int
	Offset int
}

func NewPagination

func NewPagination(page, size int) *Pagination

type PreloadCondition

type PreloadCondition struct {
	QueryParam   string // Название параметра в запросе (например "no_child")
	PreloadName  string // Название прелоада (например "Children")
	DefaultValue bool   // Значение по умолчанию, если параметр не указан
	Invert       bool   // Если true, то прелоад включается когда false
}

type QueryCondition

type QueryCondition struct {
	Field            string
	Operator         sql_enum.QueryOperator
	Value            interface{}
	Required         bool
	Transformer      utils.ValueTransformer
	UniqueIdentifier bool
}

func (*QueryCondition) SetValue

func (q *QueryCondition) SetValue(stringValues ...string) error

type QueryOptions

type QueryOptions struct {
	Conditions ConditionsMap
	Preloads   []string
	Sort       *SortOption
	Pagination *Pagination // Используем указатель для optional параметра
}

func DefaultQueryOptions

func DefaultQueryOptions() *QueryOptions

func (*QueryOptions) ApplyDefaults

func (opts *QueryOptions) ApplyDefaults() *QueryOptions

func (*QueryOptions) SetSort

func (o *QueryOptions) SetSort(field string, direction string) *QueryOptions

type QueryTag

type QueryTag struct {
	Operators        []sql_enum.QueryOperator // Поддерживаемые операторы
	ParamName        string                   // Имя параметра в запросе
	Consider         bool                     // Учитывать или нет
	UniqueIdentifier bool                     // Использовать как уникальный идентификатор запроса
	NoSortable       bool
}

type SortOption

type SortOption struct {
	Field     string
	Direction string // "ASC" или "DESC"
}

func NewSortOption

func NewSortOption(field, direction string) *SortOption

func NewSortOptionWithDefaults

func NewSortOptionWithDefaults() *SortOption

func ParseSortString

func ParseSortString(sortStr string, validFields []string) *SortOption

ParseSortString парсит строку сортировки и валидирует поля

Jump to

Keyboard shortcuts

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