api_entity

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConvertToModel added in v0.0.8

type ConvertToModel[T any] interface {
	ToModel() T
}

type FilterField

type FilterField struct {
	Field string
	Type  FilterType
	Value any
}

func (FilterField) ApplyTo

func (f FilterField) ApplyTo(c *gorm.DB) (*gorm.DB, error)

func (FilterField) Condition

func (f FilterField) Condition() string

func (FilterField) Values

func (f FilterField) Values() []any

type FilterType

type FilterType string
const (
	EQ      FilterType = "="
	NE      FilterType = "!="
	GE      FilterType = ">="
	GT      FilterType = ">"
	LE      FilterType = "<="
	LT      FilterType = "<"
	LIKE    FilterType = "LIKE"
	IN      FilterType = "IN"
	NOTIN   FilterType = "NOT IN"
	BETWEEN FilterType = "BETWEEN"
)

func (FilterType) ToCondition added in v0.0.7

func (f FilterType) ToCondition() string

type GormFilter

type GormFilter interface {
	Condition() string
	Values() []interface{}
	ApplyTo(c *gorm.DB) (*gorm.DB, error)
}

type GormRepository added in v0.0.8

type GormRepository[T RepositoryItem] interface {
	Conn() *gorm.DB
	New() T
	NewSlice() []T

	GetByID(id int64) (T, error)
	GetByIDs(ids ...int64) ([]T, error)
	GetResults(filters ...GormFilter) ([]T, error)
	ApplyFilters(filters ...GormFilter) (*gorm.DB, error)
	Count(filters ...GormFilter) (int64, error)

	Create(T) (T, error)
	Update(T) (bool, error)
	Delete(T) (bool, error)
}

type NotFilterableError added in v0.0.10

type NotFilterableError struct {
	Field string
}

func (NotFilterableError) Error added in v0.0.10

func (e NotFilterableError) Error() string

type PageFilter

type PageFilter struct {
	Page  int
	Limit int
}

func (PageFilter) ApplyTo

func (p PageFilter) ApplyTo(c *gorm.DB) (*gorm.DB, error)

func (PageFilter) Condition

func (p PageFilter) Condition() string

func (PageFilter) Values

func (p PageFilter) Values() []any

type RepositoryItem added in v0.0.8

type RepositoryItem interface {
	schema.Tabler
	GetID() int64
	IsFilterable(field string) bool
}

type WhereFilter

type WhereFilter []any

func (WhereFilter) ApplyTo

func (w WhereFilter) ApplyTo(c *gorm.DB) (*gorm.DB, error)

func (WhereFilter) Condition

func (w WhereFilter) Condition() string

func (WhereFilter) Values

func (w WhereFilter) Values() []any

Jump to

Keyboard shortcuts

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