model

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Tag = "coyote"

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name          string
	Column        string
	Label         string
	Kind          Kind
	Size          int
	Required      bool
	Nullable      bool
	PrimaryKey    bool
	AutoIncrement bool
	Generated     bool
	Sensitive     bool
	Default       string
	UploadPath    string
	Accept        string
}

func (Field) Editable

func (f Field) Editable() bool

type FieldOptions

type FieldOptions struct {
	IsFile    bool
	Path      string
	Accept    string
	Sensitive bool
	Public    bool
}

func ParseTag

func ParseTag(tag string) FieldOptions

type Fileish

type Fileish interface {
	IsFile() bool
}

type Filter

type Filter struct {
	Column string
	Op     Op
	Value  any
}

type Index

type Index struct {
	Name    string
	Columns []string
	Unique  bool
}

type Kind

type Kind string
const (
	KindString Kind = "string"
	KindText   Kind = "text"
	KindInt    Kind = "int"
	KindFloat  Kind = "float"
	KindBool   Kind = "bool"
	KindTime   Kind = "time"
	KindBytes  Kind = "bytes"
	KindFile   Kind = "file"
)

func KindOf

func KindOf(t reflect.Type) (Kind, bool)

type Model

type Model struct {
	Entity any
	Table  string
	Alias  string
}

func Named

func Named(table string, entity any) Model

func Of

func Of(entity any) Model

func On

func On(alias string, entity any) Model

func (Model) NamedOn

func (m Model) NamedOn(alias, table string) Model

type Op

type Op string
const (
	Eq      Op = "eq"
	Ne      Op = "ne"
	Lt      Op = "lt"
	Lte     Op = "lte"
	Gt      Op = "gt"
	Gte     Op = "gte"
	In      Op = "in"
	Like    Op = "like"
	Null    Op = "null"
	NotNull Op = "notnull"
)

type Optioner

type Optioner interface {
	Options(ctx context.Context, relation Relation, limit int) ([]Record, error)
}

type Ordering

type Ordering struct {
	Column string
	Desc   bool
}

type Page

type Page struct {
	Records []Record
	Total   int64
}

type Query

type Query struct {
	Limit   int
	Offset  int
	Order   string
	Sort    string
	Select  []string
	Filters []Filter
	AnyOf   []Filter
	With    []string
}

type Record

type Record map[string]any

func (Record) Bool

func (r Record) Bool(column string) bool

func (Record) Get

func (r Record) Get(column string) any

func (Record) String

func (r Record) String(column string) string

type Registry

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

func NewRegistry

func NewRegistry(models ...Model) *Registry

func (*Registry) Add

func (r *Registry) Add(models ...Model)

func (*Registry) AliasOf

func (r *Registry) AliasOf(entity any) string

func (*Registry) Aliases

func (r *Registry) Aliases() []string

func (*Registry) All

func (r *Registry) All() []Model

func (*Registry) Entities

func (r *Registry) Entities() []any

func (*Registry) For

func (r *Registry) For(alias string) []Model

func (*Registry) Len

func (r *Registry) Len() int

type Relation

type Relation struct {
	Column      string
	Target      string
	TargetKey   string
	LabelColumn string
}

type Schema

type Schema struct {
	Table     string
	Slug      string
	Label     string
	Plural    string
	Fields    []Field
	Indexes   []Index
	Relations []Relation
	Key       Field
	// contains filtered or unexported fields
}

func Describe

func Describe(handle *gorm.DB, entity any) (*Schema, error)

func (*Schema) BindableFields

func (s *Schema) BindableFields(only, except []string) []Field

func (*Schema) Columns

func (s *Schema) Columns() []string

func (*Schema) DisplayFields

func (s *Schema) DisplayFields(includeKey bool) []Field

func (*Schema) Field

func (s *Schema) Field(column string) (Field, bool)

func (*Schema) FormFields

func (s *Schema) FormFields() []Field

func (*Schema) HasColumn

func (s *Schema) HasColumn(name string) bool

func (*Schema) Hide

func (s *Schema) Hide(columns []string)

func (*Schema) ListFields

func (s *Schema) ListFields() []Field

func (*Schema) OrderBy

func (s *Schema) OrderBy(candidate string) []Ordering

func (*Schema) Relation

func (s *Schema) Relation(column string) (Relation, bool)

func (*Schema) SetListColumns

func (s *Schema) SetListColumns(columns []string)

func (*Schema) SortColumn

func (s *Schema) SortColumn(candidate string) (string, string, bool)

func (*Schema) Visible

func (s *Schema) Visible() []Field

type Store

type Store interface {
	List(ctx context.Context, schema *Schema, query Query) (Page, error)
	Find(ctx context.Context, schema *Schema, id string) (Record, error)
	Insert(ctx context.Context, schema *Schema, record Record) (string, error)
	Update(ctx context.Context, schema *Schema, id string, record Record) error
	Delete(ctx context.Context, schema *Schema, id string) error
	Count(ctx context.Context, schema *Schema, query Query) (int64, error)
	Exists(ctx context.Context, schema *Schema, query Query) (bool, error)
	First(ctx context.Context, schema *Schema, query Query) (Record, error)
	WithTx(tx *gorm.DB) Store
}

Jump to

Keyboard shortcuts

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