entnum

package module
v0.0.0-...-5209014 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: MIT Imports: 5 Imported by: 0

README

entnum

Under development.

entnum is an ent extension that makes ent use better enums.

This extension has only been tested on SQL systems.

Before

// Color defines the type for the "color" enum field.
type Color string

// Status values.
const (
	ColorRed   Status = "red"
	ColorGreen Status = "green"
	ColorBlue  Status = "blue"
)

After

// Color defines the type for the "color" enum field.
type Color enum.Member[string]

// Color values.
var (
  color      = enum.NewBuilder[string, Color]()
  ColorRed   = color.Add(Color{"red"})
  ColorGreen = color.Add(Color{"green"})
  ColorBlue  = color.Add(Color{"blue"})
  Colors     = color.Enum()
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TemplateFuncs = template.FuncMap{
		"isEnum": IsEnum,
	}
)

Functions

func IsEnum

func IsEnum(f gen.Field) bool

Types

type Extension

type Extension struct {
	entc.DefaultExtension
}

func New

func New(opts ...Option) (*Extension, error)

New creates a new entnum.Extension to use with entc.

func (*Extension) Templates

func (e *Extension) Templates() []*gen.Template

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option for future use.

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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