enums

package
v0.41.2 Latest Latest
Warning

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

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

Documentation

Overview

Package enums holds two enum types exactly as `aru make:enum` writes them, so that what depends on the enum contract is tested against the file a project actually gets rather than against a hand-written stand-in.

Nothing here is edited. Each type is copied in as generated, which is what makes a failure here mean the generator and the contract have drifted apart -- the only failure worth having in this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InvoiceStatus

type InvoiceStatus string

InvoiceStatus is the closed set of values the column may hold.

Go has no enum keyword, so this is the shape that gets the guarantee anyway: a named type, constants that are the only valid values, and a Scan/Value pair so a value the application does not know about is an error at the read rather than a zero value that silently behaves like the first case.

That last part is the whole reason the file is this long: nothing refuses an unknown value unless the type does, and a plain `type InvoiceStatus string` accepts anything the database hands it.

const (
	InvoiceStatusDraft InvoiceStatus = "draft"
	InvoiceStatusSent  InvoiceStatus = "sent"
	InvoiceStatusPaid  InvoiceStatus = "paid"
	InvoiceStatusVoid  InvoiceStatus = "void"
)

The values. Stored exactly as written -- renaming a constant must never rewrite a column.

func InvoiceStatusValues

func InvoiceStatusValues() []InvoiceStatus

InvoiceStatusValues lists them in declaration order.

It feeds a <select> in a kyse view and it is what a test asserts against, so adding a value without deciding what the form and the migration do about it shows up as a failure.

func ParseInvoiceStatus

func ParseInvoiceStatus(s string) (InvoiceStatus, error)

ParseInvoiceStatus turns request input into the type, or says why it cannot.

app/Http/Requests calls it, so a value outside the set becomes a field error the form can show rather than a row.

func (InvoiceStatus) Label

func (v InvoiceStatus) Label() string

Label is what a form shows.

Separate from String on purpose: the stored value is a contract with the database and with every consumer of an event, and the label is a contract with nobody. Changing a label must not be able to change a row.

func (*InvoiceStatus) Scan

func (v *InvoiceStatus) Scan(src any) error

Scan implements sql.Scanner.

A value the application does not know about is an error here, at the row that has it, rather than a silent fallback three layers up. That is usually a migration that added a value the binary being rolled out does not have yet, which is why a migration must stay compatible with the previous binary.

func (InvoiceStatus) String

func (v InvoiceStatus) String() string

String is the stored value, so fmt and a view print it unchanged.

func (InvoiceStatus) Valid

func (v InvoiceStatus) Valid() bool

Valid reports whether v is one of the values.

func (InvoiceStatus) Value

func (v InvoiceStatus) Value() (driver.Value, error)

Value implements driver.Valuer. It refuses to write a value outside the set, which is what keeps a zero-valued struct from putting an empty string in the column.

type Priority

type Priority int

Priority is the closed set of values the column may hold.

Go has no enum keyword, so this is the shape that gets the guarantee anyway: a named type, constants that are the only valid values, and a Scan/Value pair so a value the application does not know about is an error at the read rather than a zero value that silently behaves like the first case.

That last part is the whole reason the file is this long: nothing refuses an unknown value unless the type does, and a plain `type Priority int` accepts anything the database hands it.

const (
	PriorityLow    Priority = 1
	PriorityNormal Priority = 2
	PriorityHigh   Priority = 3
)

The values. The numbers are explicit and never iota: iota renumbers everything below an insertion, and the numbers are already in the database.

func ParsePriority

func ParsePriority(s string) (Priority, error)

ParsePriority turns request input into the type, or says why it cannot.

app/Http/Requests calls it, so a value outside the set becomes a field error the form can show rather than a row.

func PriorityValues

func PriorityValues() []Priority

PriorityValues lists them in declaration order.

It feeds a <select> in a kyse view and it is what a test asserts against, so adding a value without deciding what the form and the migration do about it shows up as a failure.

func (Priority) Label

func (v Priority) Label() string

Label is what a form shows.

Separate from String on purpose: the stored value is a contract with the database and with every consumer of an event, and the label is a contract with nobody. Changing a label must not be able to change a row.

func (*Priority) Scan

func (v *Priority) Scan(src any) error

Scan implements sql.Scanner.

A value the application does not know about is an error here, at the row that has it, rather than a silent fallback three layers up. That is usually a migration that added a value the binary being rolled out does not have yet, which is why a migration must stay compatible with the previous binary.

func (Priority) String

func (v Priority) String() string

String is the name of the value, because the stored one is a number and a number in a log is a lookup somebody has to do at three in the morning.

func (Priority) Valid

func (v Priority) Valid() bool

Valid reports whether v is one of the values.

func (Priority) Value

func (v Priority) Value() (driver.Value, error)

Value implements driver.Valuer. It refuses to write a value outside the set, which is what keeps a zero-valued struct from putting a zero in the column.

Jump to

Keyboard shortcuts

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