sort

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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) String

func (od OrderDirection) String() string

String returns the string representation of OrderDirection.

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.

func (OrderSpec) IsValid

func (os OrderSpec) IsValid() bool

IsValid checks if the OrderSpec is valid. An OrderSpec is valid if it has either a Column or an Expression, but not both.

Jump to

Keyboard shortcuts

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