Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidOrderDirection = errors.New("invalid OrderDirection value")
ErrInvalidOrderDirection is returned when an invalid OrderDirection value is provided.
Functions ¶
This section is empty.
Types ¶
type NullsOrder ¶
type NullsOrder int
NullsOrder represents how to handle NULL values in ordering. Different databases have different default behaviors for NULL values, so explicit specification ensures consistent behavior across databases.
const ( // NullsDefault uses database default behavior for NULLs. // WARNING: This may cause inconsistent behavior across different databases. // PostgreSQL: ASC=NULLS LAST, DESC=NULLS FIRST // MySQL/SQLite: ASC=NULLS FIRST, DESC=NULLS LAST // Oracle: ASC=NULLS LAST, DESC=NULLS FIRST. NullsDefault NullsOrder = iota // NullsFirst places NULL values before non-NULL values in the result set. NullsFirst // NullsLast places NULL values after non-NULL values in the result set. NullsLast )
func (NullsOrder) String ¶
func (no NullsOrder) String() string
String returns the string representation of NullsOrder.
type OrderDirection ¶
type OrderDirection int
OrderDirection represents the direction of ordering in SQL queries. It defines whether results should be sorted in ascending or descending order.
const ( // OrderAsc represents ascending order (A-Z, 0-9, oldest to newest). OrderAsc OrderDirection = iota // OrderDesc represents descending order (Z-A, 9-0, newest to oldest). OrderDesc )
func (OrderDirection) MarshalJSON ¶ added in v0.7.0
func (od OrderDirection) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface for OrderDirection. It delegates to MarshalText and wraps the result as a JSON string.
func (OrderDirection) MarshalText ¶ added in v0.7.0
func (od OrderDirection) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler interface for OrderDirection. It marshals OrderDirection as a lowercase string ("asc" or "desc").
func (OrderDirection) String ¶
func (od OrderDirection) String() string
String returns the string representation of OrderDirection.
func (*OrderDirection) UnmarshalJSON ¶ added in v0.7.0
func (od *OrderDirection) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler interface for OrderDirection. It accepts string values "asc", "ASC", "desc", "DESC" (case-insensitive). This method delegates to UnmarshalText for the actual conversion logic.
func (*OrderDirection) UnmarshalText ¶ added in v0.7.0
func (od *OrderDirection) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler interface for OrderDirection. It accepts string values "asc", "ASC", "desc", "DESC" (case-insensitive).
type OrderSpec ¶
type OrderSpec struct {
// Column is the column name to order by.
// Should be empty if Expression is used instead.
Column string
// Direction specifies the ordering direction (ASC or DESC).
Direction OrderDirection
// NullsOrder specifies how to handle NULL values in the ordering.
// Use NullsDefault to rely on database defaults (not recommended for cross-database compatibility).
NullsOrder NullsOrder
}
OrderSpec represents a ordering specification for a single column. It encapsulates all the information needed to generate the ORDER BY clause for one item.