index

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package index holds the index builders used in an entity schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	// contains filtered or unexported fields
}

Column is a single indexed column together with its sort direction.

func (Column) GetName

func (c Column) GetName() string

GetName returns the column name.

func (Column) IsDesc

func (c Column) IsDesc() bool

IsDesc reports if the column is sorted descending.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index holds the state of one index.

func (Index) Asc

func (i Index) Asc(fields ...string) IndexOperations

Asc appends columns sorted ascending.

func (Index) Desc

func (i Index) Desc(fields ...string) IndexOperations

Desc appends columns sorted descending.

func (Index) GetColumns

func (i Index) GetColumns() []Column

GetColumns returns the columns with their sort direction, in order.

func (Index) GetFields

func (i Index) GetFields() []string

GetFields returns just the column names, in order.

func (Index) GetName

func (i Index) GetName() string

GetName returns the custom index name, or "" when auto-generated.

func (Index) GetType

func (i Index) GetType() Type

GetType returns the index kind, primary or index.

func (Index) Index

func (Index) Index()

marker method for sealed interface

func (Index) IsUnique

func (i Index) IsUnique() bool

IsUnique reports if the index is a unique constraint.

func (Index) Name

func (i Index) Name(name string) IndexOperations

Name overrides the auto-generated index name.

func (Index) Unique

func (i Index) Unique() IndexOperations

Unique turns the index into a unique constraint.

type IndexBuilder

type IndexBuilder interface {
	Index()
}

IndexBuilder is implemented by every index.

func Primary

func Primary(fields ...string) IndexBuilder

Primary declares the primary key over the given fields. It replaces the generated id column, which is left out of the table.

type IndexOperations

type IndexOperations interface {
	IndexBuilder
	// Unique turns the index into a unique constraint.
	Unique() IndexOperations
	// Name overrides the auto-generated index name
	Name(name string) IndexOperations
	// Asc appends columns sorted ascending.
	Asc(fields ...string) IndexOperations
	// Desc appends columns sorted descending.
	Desc(fields ...string) IndexOperations
}

IndexOperations exposes the fluent modifiers available on a secondary index.

func Asc added in v0.0.6

func Asc(fields ...string) IndexOperations

Asc declares a secondary index whose first columns are sorted ascending. Chain Asc or Desc to append more columns, e.g. Asc("is_active").Desc("created_at").

func Desc added in v0.0.6

func Desc(fields ...string) IndexOperations

Desc declares a secondary index whose first columns are sorted descending. Chain Asc or Desc to append more columns, e.g. Desc("created_at").Asc("id").

type Type

type Type string

Type tells which kind of index is described.

const (
	// TypePrimary marks a (compound) primary key.
	TypePrimary Type = "primary"
	// TypeIndex is a regular secondary index (optionally unique).
	TypeIndex Type = "index"
)

Jump to

Keyboard shortcuts

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