focus

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CreateView view = iota + 1
	UpdateView
	ListView
)

Variables

This section is empty.

Functions

func GetPKs

func GetPKs(obj any, pkName string) ([]any, error)

GetPKs получение первичных ключей

func GetValidationRules

func GetValidationRules(model Model, filter func(field *Field) bool) rules

func RawType

func RawType(elem reflect.Type) reflect.Type

RawType извлекает тип элемента из указателей и срезов

Types

type Association

type Association struct {
	Type           AssociationType // Type Тип ассоциации, может быть belongsTo, hasOne, hasMany, manyToMany (как в gorm)
	Model          *Model          // Model Модель, к которой происходит ассоциация
	Many2Many      string          // Many2Many Название промежуточной таблицы для отношения many2many
	ForeignKey     string          // ForeignKey Внешний ключ ассоциации
	References     string          // References Референс внешнего ключа
	JoinForeignKey string          // JoinForeignKey Внешний ключ в промежуточной таблице
	JoinReferences string          // JoinReferences Референс в промежуточной таблице
	JoinSort       string          // JoinSort сортировка ассоциации (только для типа many2many)
	// contains filtered or unexported fields
}

Ассоциация модели

type AssociationType

type AssociationType int
const (
	None AssociationType = iota
	BelongsTo
	HasOne
	HasMany
	ManyToMany
)

type Field

type Field struct {
	Title            string         // Title Название поля (как оно будет отображаться)
	Column           string         // Column Название колонки в таблице (в базе)
	Code             string         // Code код поля
	Sortable         bool           // Sortable Участвует в сортировке или нет (в списке элементов)
	Filterable       bool           // Filterable Участвует в фильтрации или нет (в списке элементов)
	Position         int            // Position Порядок отображения в списке и карточке
	Block            string         // Block Блок, в котором располагается поле
	IsUnique         bool           // IsUnique Уникальность
	IsMedia          bool           // IsMedia поле является ассоциацией к медиа
	IsTime           bool           // IsTime поле является датой/временем
	Hidden           []view         // Hidden описывает, где поле не отображается
	Disabled         []view         // Disabled описывает, где поле не доступно для редактирования
	View             form.FieldType // View тип отображения
	ViewExtra        map[string]any // ViewExtra доп параметры отображения
	Multiple         bool           // Multiple множественное
	Model            *Model         // Model Описание модели поля
	*FloatProperties                // FloatProperties настройки для типа float

	Association *Association // Association Описание ассоциации
	// contains filtered or unexported fields
}

func (Field) Name

func (f Field) Name() string

Name получение наименования поля в объекте модели

func (Field) NewValue

func (f Field) NewValue(value any) (any, error)

NewValue приводит переданное значение к типу поля

func (Field) RawKind

func (f Field) RawKind() reflect.Kind

Field.RawKind извлекает вид элемента

func (Field) RawType

func (f Field) RawType() reflect.Type

Field.RawType извлекает вид элемента

func (*Field) Scan

func (f *Field) Scan(structField reflect.StructField)

Scan заполнение поля значениями на основе структуры поля

func (*Field) ScanTag

func (f *Field) ScanTag(tagString string)

ScanTag заполнение поля значениями на основе тегов

func (Field) Slice

func (f Field) Slice(values []any) ([]any, error)

Slice приводит переданный срез значений к срезу типа поля

type FieldFiller

type FieldFiller struct {
	Fill    func(field *Field, value string) // Fill проставление значения на основе значения
	Default func(field *Field)               // Default проставление значения по умолчанию
	Code    string
}

type FieldType

type FieldType string

type Fields

type Fields []*Field

func (Fields) GetByCode

func (f Fields) GetByCode(code string) *Field

type FillFunc

type FillFunc func(*Field, string)

type FloatProperties

type FloatProperties struct {
	Step      float64
	Precision int
}

type Focusable

type Focusable interface {
	TableName() string
	ModelTitle() string
}

type Model

type Model struct {
	TableName  string `json:"tableName"`  // Название таблицы
	Code       string `json:"code"`       // Код модели
	Title      string `json:"name"`       // Название модели для отображения
	PrimaryKey *Field `json:"primaryKey"` // Первичный ключ
	Fields     Fields `json:"fields"`     // Поля модели, кроме первичного ключа
	// contains filtered or unexported fields
}

func NewModel

func NewModel(t reflect.Type) *Model

NewModel конструктор модели

func (Model) ElementToMap

func (m Model) ElementToMap(modelElement any, filter func(field Field) bool) (model map[string]any, err error)

ElementToMap преобразование элемента модели в карту

func (Model) ElementsSlice

func (m Model) ElementsSlice(modelElementsMaps []map[string]any) (any, error)

Model.ElementsSlice получение среза элементов

func (Model) NewElement

func (m Model) NewElement(fieldsMap map[string]any, filter func(field *Field) bool) (modelElement any, err error)

Model.NewElement возвращает указатель на элемент модели

func (Model) Type

func (m Model) Type() reflect.Type

func (Model) UpdateElement

func (m Model) UpdateElement(dst any, src any, filter func(field *Field) bool) error

Model.UpdateElement проставляет поля из source в destination

type ModelsRegistry

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

func NewModelsRegistry

func NewModelsRegistry(supportMedia bool) *ModelsRegistry

NewModelsRegistry конструктор

func (ModelsRegistry) GetModel

func (r ModelsRegistry) GetModel(code string) *Model

GetModel получение модели по коду

func (ModelsRegistry) ListModels

func (r ModelsRegistry) ListModels() []*Model

ListModels получение всех зарегистрированных моделей

func (*ModelsRegistry) NewModel

func (r *ModelsRegistry) NewModel(t reflect.Type)

ModelsRegistry.NewModel сканирование модели

func (*ModelsRegistry) Register

func (r *ModelsRegistry) Register(items ...any)

Register регистрация моделей

Jump to

Keyboard shortcuts

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