db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

AllPredicates is a slice of all available predicates.

DirectionsToDB is a map of order directions to database order directions.

View Source
var EqualAndNotEqualPredicates = []Predicate{Equal, Eq, NotEqual, Ne}

EqualAndNotEqualPredicates is a slice of predicates that allow both equality and inequality.

View Source
var ErrInvalidDatabaseSelectorTranslation = apierror.NewAPIError(
	"INVALID_DATABASE_SELECTOR_TRANSLATION",
)

ErrInvalidDatabaseSelectorTranslation indicates that the translation of a database selector failed.

View Source
var ErrInvalidDatabaseUpdateTranslation = apierror.NewAPIError(
	"INVALID_DATABASE_UPDATE_TRANSLATION",
)

ErrInvalidDatabaseUpdateTranslation is used to indicate that the translation of a database update failed.

View Source
var ErrInvalidOrderField = apierror.NewAPIError("INVALID_ORDER_FIELD")

ErrInvalidOrderField is returned when a field is not allowed.

View Source
var ErrInvalidPredicate = apierror.NewAPIError("INVALID_PREDICATE")

ErrInvalidPredicate is returned when a predicate is not allowed.

View Source
var ErrInvalidSelectorField = apierror.NewAPIError("INVALID_SELECTOR_FIELD")

ErrInvalidSelectorField is returned when a field is not allowed.

View Source
var ErrMaxPageLimitExceeded = apierror.NewAPIError("MAX_PAGE_LIMIT_EXCEEDED")

ErrMaxPageLimitExceeded is returned when a page limit is exceeded.

View Source
var ErrPredicateNotAllowed = apierror.NewAPIError("PREDICATE_NOT_ALLOWED")

ErrPredicateNotAllowed is returned when a predicate is not allowed.

View Source
var OnlyEqualPredicates = []Predicate{Equal, Eq}

OnlyEqualPredicates is a slice of predicates that only allow equality.

View Source
var OnlyGreaterPredicates = []Predicate{GreaterOrEqual, Ge, Greater, Gt}

OnlyGreaterPredicates is a slice of predicates that only allow greater values.

View Source
var OnlyInAndNotInPredicates = []Predicate{In, NotIn}

OnlyInAndNotInPredicates is a slice of predicates that only allow IN and NOT_IN.

View Source
var OnlyLessPredicates = []Predicate{LessOrEqual, Le, Less, Lt}

OnlyLessPredicates is a slice of predicates that only allow less values.

ToDBPredicates maps API-level predicates to database predicates.

Functions

This section is empty.

Types

type APISelectors

type APISelectors map[string]Selector

APISelectors represents a collection of selectors used for filtering data. It is a map where the key is the field name and the value is the selector.

func (APISelectors) AddSelector

func (s APISelectors) AddSelector(
	field string, predicate Predicate, value any,
) APISelectors

AddSelector adds a new selector to the collection of selectors.

Parameters:

  • field: The field name.
  • predicate: The predicate to use.
  • value: The value to filter on.

Returns:

  • APISelectors: A new collection of selectors with the new selector added.

func (APISelectors) ToDBSelectors

func (s APISelectors) ToDBSelectors(
	apiToDBFieldMap map[string]APIToDBField,
) ([]db.Selector, error)

ToDBSelectors converts a slice of API-level selectors to database selectors.

Parameters:

  • apiToDBFieldMap: A map translating API field names to their corresponding database field definitions.

Returns:

  • []types.Selector: A slice of types.Selector, which represents the translated database selectors.
  • error: An error if any validation fails, such as invalid predicates or unknown fields.

type APIToDBField

type APIToDBField struct {
	Table  string
	Column string
}

APIToDBField is used to translate between API field and database field.

type APIUpdates

type APIUpdates map[string]any

APIUpdates represents a list of updates to apply to a database entity.

func (APIUpdates) ToDBUpdates

func (updates APIUpdates) ToDBUpdates(
	apiToDBFieldMap map[string]APIToDBField,
) ([]db.Update, error)

ToDBUpdates translates a list of updates to a database update list and returns an error if the translation fails.

Parameters:

  • updates: The list of updates to translate.
  • apiToDBFieldMap: The mapping of API field names to database field names.

Returns:

  • []Update: A list of database entity updates.
  • error: An error if any field translation fails.

type Direction

type Direction string

Direction is used to specify the direction of the order.

const (
	DirectionAsc        Direction = "asc"
	DirectionAscending  Direction = "ascending"
	DirectionDesc       Direction = "desc"
	DirectionDescending Direction = "descending"
)

Available order directions.

func (Direction) String

func (o Direction) String() string

String returns the string representation of the order direction.

Returns:

  • string: The string representation of the order direction.

type ErrInvalidDatabaseSelectorTranslationData

type ErrInvalidDatabaseSelectorTranslationData struct {
	Field string `json:"field"`
}

ErrInvalidDatabaseSelectorTranslationData is the data for the ErrInvalidDatabaseSelectorTranslation error.

type ErrInvalidDatabaseUpdateTranslationData

type ErrInvalidDatabaseUpdateTranslationData struct {
	Field string `json:"field"`
}

ErrInvalidDatabaseUpdateTranslationData is the data for the ErrInvalidDatabaseUpdateTranslation error.

type ErrInvalidOrderFieldData

type ErrInvalidOrderFieldData struct {
	Field string `json:"field"`
}

ErrInvalidOrderFieldData is the data for the ErrInvalidOrderField error.

type ErrInvalidPredicateData

type ErrInvalidPredicateData struct {
	Predicate Predicate `json:""`
}

ErrInvalidPredicateData is the data for the ErrInvalidPredicate error.

type ErrInvalidSelectorFieldData

type ErrInvalidSelectorFieldData struct {
	Field string `json:"field"`
}

ErrInvalidSelectorFieldData is the data for the ErrInvalidSelectorField error.

type ErrMaxPageLimitExceededData

type ErrMaxPageLimitExceededData struct {
	MaxLimit int `json:"max_limit"`
}

ErrMaxPageLimitExceededData is the data for the ErrMaxPageLimitExceeded error.

type ErrPredicateNotAllowedData

type ErrPredicateNotAllowedData struct {
	Predicate Predicate `json:"predicate"`
}

ErrPredicateNotAllowedData is the data for the ErrPredicateNotAllowed error.

type Orders

type Orders map[string]Direction

Orders is a map of field names to order directions.

func (Orders) ToDBOrders

func (o Orders) ToDBOrders(
	apiToDBFieldMap map[string]APIToDBField,
) ([]db.Order, error)

ToDBOrders translates the provided orders into database orders. It returns an error if any of the orders are invalid.

Parameters:

  • apiToDBFieldMap: The mapping of API field names to database field names.

Returns:

  • []Order: The list of database orders.
  • error: An error if any of the orders are invalid.

func (Orders) TranslateToDBOrders

func (o Orders) TranslateToDBOrders(
	apiToDBFieldMap map[string]APIToDBField,
) ([]db.Order, error)

TranslateToDBOrders translates the provided orders into database orders. It also returns an error if any of the orders are invalid.

Parameters:

  • orders: The list of orders to translate.
  • allowedOrderFields: The list of allowed order fields.
  • apiToDBFieldMap: The mapping of API field names to database field names.

Returns:

  • []Order: The list of database orders.
  • error: An error if any of the orders are invalid.

type Page

type Page struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

Page represents a pagination input.

func (*Page) ToDBPage

func (p *Page) ToDBPage() *db.Page

ToDBPage converts a Page to database Page.

Returns:

  • *Page: The database Page.

type Predicate

type Predicate string

Predicate is a string representation of a filtering predicate.

const (
	Greater        Predicate = ">"
	Gt             Predicate = "gt"
	GreaterOrEqual Predicate = ">="
	Ge             Predicate = "ge"
	Equal          Predicate = "="
	Eq             Predicate = "eq"
	NotEqual       Predicate = "!="
	Ne             Predicate = "ne"
	Less           Predicate = "<"
	Lt             Predicate = "LT"
	LessOrEqual    Predicate = "<="
	Le             Predicate = "le"
	In             Predicate = "in"
	NotIn          Predicate = "not_in"
)

Predicates for filtering data.

func (Predicate) String

func (p Predicate) String() string

String returns the string representation of the predicate.

Returns:

  • string: The string representation of the predicate.

type Predicates

type Predicates []Predicate

Predicates is a slice of Predicate values.

func (Predicates) StrSlice

func (p Predicates) StrSlice() []string

StrSlice returns a slice of strings representing the predicates.

Returns:

  • []string: A slice of strings representing the predicates.

func (Predicates) String

func (p Predicates) String() string

String returns a string representation of the predicates.

Returns:

  • string: A comma-separated string of the predicates.

type Selector

type Selector struct {
	Predicate Predicate `json:"predicate"` // The predicate to use.
	Value     any       `json:"value"`     // The value to filter on.
}

Selector represents a data selector that specifies criteria for filtering data based on fields, predicates, and values.

func NewSelector

func NewSelector(predicate Predicate, value any) *Selector

NewSelector creates a new API selector with the provided predicate and value.

Parameters:

  • predicate: The predicate to use.
  • value: The value to filter on.

Returns:

  • *APISelector: A new selector.

func (Selector) String

func (s Selector) String() string

String returns a string representation of the selector. It is useful for debugging and logging purposes.

Returns:

  • string: A formatted string showing the field, predicate, and value.

Jump to

Keyboard shortcuts

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