object

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilterOpIsNot          = "is not"
	FilterOpEqual          = "="
	FilterOpNotEqual       = "<>"
	FilterOpIn             = "in"
	FilterOpNotIn          = "not_in"
	FilterOpGreater        = ">"
	FilterOpGreaterOrEqual = ">="
	FilterOpLess           = "<"
	FilterOpLessOrEqual    = "<="
	FilterOpLike           = "like"
	FilterOpBetween        = "between"
)
View Source
const (
	OrderOpDesc = "desc"
	OrderOpAsc  = "asc"
)
View Source
const (
	GET    = 1 << 1
	CREATE = 1 << 2
	EDIT   = 1 << 3
	DELETE = 1 << 4
	QUERY  = 1 << 5
)
View Source
const (
	DefaultQueryLimit = 102400 // 100k
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAccessCheck

type AdminAccessCheck func(c *fiber.Ctx, obj *AdminObject) error

Access control

type AdminAction

type AdminAction struct {
	Path          string             `json:"path"`
	Name          string             `json:"name"`
	Label         string             `json:"label,omitempty"`
	Icon          string             `json:"icon,omitempty"`
	Class         string             `json:"class,omitempty"`
	WithoutObject bool               `json:"withoutObject"`
	Handler       AdminActionHandler `json:"-"`
}

type AdminActionHandler

type AdminActionHandler func(c *fiber.Ctx, obj any) (any, error)

type AdminAttribute

type AdminAttribute struct {
	Default      any                 `json:"default,omitempty"`
	Choices      []AdminSelectOption `json:"choices,omitempty"`
	SingleChoice bool                `json:"singleChoice,omitempty"`
	Widget       string              `json:"widget,omitempty"`
	FilterWidget string              `json:"filterWidget,omitempty"`
	Help         string              `json:"help,omitempty"`
}

type AdminBuildContext

type AdminBuildContext func(*fiber.Ctx, map[string]any) map[string]any

type AdminField

type AdminField struct {
	Placeholder string          `json:"placeholder,omitempty"` // Placeholder of the filed
	Label       string          `json:"label"`                 // Label of the filed
	NotColumn   bool            `json:"notColumn,omitempty"`   // Not a column
	Required    bool            `json:"required,omitempty"`
	Name        string          `json:"name"`
	Type        string          `json:"type"`
	Tag         string          `json:"tag,omitempty"`
	Attribute   *AdminAttribute `json:"attribute,omitempty"`
	CanNull     bool            `json:"canNull,omitempty"`
	IsArray     bool            `json:"isArray,omitempty"`
	Primary     bool            `json:"primary,omitempty"`
	Foreign     *AdminForeign   `json:"foreign,omitempty"`
	IsAutoID    bool            `json:"isAutoId,omitempty"`
	IsPtr       bool            `json:"isPtr,omitempty"`
	ElemType    reflect.Type    `json:"-"`
	FieldName   string          `json:"-"`
}

type AdminForeign

type AdminForeign struct {
	Path       string `json:"path"`
	Field      string `json:"field"`
	FieldName  string `json:"-"`
	ForeignKey string `json:"-"`
}

type AdminIcon

type AdminIcon struct {
	Url string `json:"url,omitempty"`
	SVG string `json:"svg,omitempty"`
}

type AdminObject

type AdminObject struct {
	Model       any             `json:"-"`
	Group       string          `json:"group"`               // Group name
	Name        string          `json:"name"`                // Name of the object
	Desc        string          `json:"desc,omitempty"`      // Description
	Path        string          `json:"path"`                // Path prefix
	Shows       []string        `json:"shows"`               // Show fields
	Orders      []Order         `json:"orders"`              // Default orders of the object
	Editables   []string        `json:"editables"`           // Editable fields
	Filterables []string        `json:"filterables"`         // Filterable fields
	Orderables  []string        `json:"orderables"`          // Orderable fields, can override Orders
	Searchables []string        `json:"searchables"`         // Searchable fields
	Requireds   []string        `json:"requireds,omitempty"` // Required fields
	PrimaryKeys []string        `json:"primaryKeys"`         // Primary keys name
	UniqueKeys  []string        `json:"uniqueKeys"`          // Primary keys name
	PluralName  string          `json:"pluralName"`
	Fields      []AdminField    `json:"fields"`
	EditPage    string          `json:"editpage,omitempty"`
	ListPage    string          `json:"listpage,omitempty"`
	Scripts     []AdminScript   `json:"scripts,omitempty"`
	Styles      []string        `json:"styles,omitempty"`
	Permissions map[string]bool `json:"permissions,omitempty"`
	Actions     []AdminAction   `json:"actions,omitempty"`
	Icon        *AdminIcon      `json:"icon,omitempty"`
	Invisible   bool            `json:"invisible,omitempty"`

	Attributes       map[string]AdminAttribute `json:"-"` // Field's extra attributes
	AccessCheck      AdminAccessCheck          `json:"-"` // Access control function
	GetDB            GetDB                     `json:"-"`
	BeforeCreate     BeforeCreateFunc          `json:"-"`
	BeforeRender     BeforeRenderFunc          `json:"-"`
	BeforeUpdate     BeforeUpdateFunc          `json:"-"`
	BeforeDelete     BeforeDeleteFunc          `json:"-"`
	TableName        string                    `json:"-"`
	ModelElem        reflect.Type              `json:"-"`
	Ignores          map[string]bool           `json:"-"`
	PrimaryKeyMaping map[string]string         `json:"-"`
	MarkDeletedField string                    `json:"-"`
	Weight           int                       `json:"-"`
}

type AdminQueryResult

type AdminQueryResult struct {
	TotalCount int              `json:"total,omitempty"`
	Pos        int              `json:"pos,omitempty"`
	Limit      int              `json:"limit,omitempty"`
	Keyword    string           `json:"keyword,omitempty"`
	Items      []map[string]any `json:"items"`
	Objects    []any            `json:"-"`
}

type AdminScript

type AdminScript struct {
	Src    string `json:"src"`
	Onload bool   `json:"onload,omitempty"`
}

type AdminSelectOption

type AdminSelectOption struct {
	Label string `json:"label"`
	Value any    `json:"value"`
}

type AdminValue

type AdminValue struct {
	Value any    `json:"value"`
	Label string `json:"label,omitempty"`
}

type BeforeCreateFunc

type BeforeCreateFunc func(ctx *fiber.Ctx, vptr any) error

type BeforeDeleteFunc

type BeforeDeleteFunc func(ctx *fiber.Ctx, vptr any) error

type BeforeQueryRenderFunc

type BeforeQueryRenderFunc func(ctx *fiber.Ctx, r *QueryResult) (any, error)

type BeforeRenderFunc

type BeforeRenderFunc func(ctx *fiber.Ctx, vptr any) (any, error)

type BeforeUpdateFunc

type BeforeUpdateFunc func(ctx *fiber.Ctx, vptr any, vals map[string]any) error

type ContentIcon

type ContentIcon AdminIcon

func (*ContentIcon) Scan

func (s *ContentIcon) Scan(input interface{}) error

func (ContentIcon) Value

func (s ContentIcon) Value() (driver.Value, error)

type Filter

type Filter struct {
	IsTimeType bool   `json:"-"`
	Name       string `json:"name"`
	Op         string `json:"op"`
	Value      any    `json:"value"`
}

func (*Filter) GetQuery

func (f *Filter) GetQuery() string

GetQuery return the combined filter SQL statement. such as "age >= ?", "name IN ?".

type GetDB

type GetDB func(c *fiber.Ctx, isCreate bool) *gorm.DB // designed for group

type Order

type Order struct {
	Name string `json:"name"`
	Op   string `json:"op"`
}

func (*Order) GetQuery

func (f *Order) GetQuery() string

GetQuery return the combined order SQL statement. such as "id DESC".

type PrepareQuery

type PrepareQuery func(db *gorm.DB, c *fiber.Ctx) (*gorm.DB, *QueryForm, error)

type QueryForm

type QueryForm struct {
	Pos          int      `json:"pos"`
	Limit        int      `json:"limit"`
	Keyword      string   `json:"keyword,omitempty"`
	Filters      []Filter `json:"filters,omitempty"`
	Orders       []Order  `json:"orders,omitempty"`
	ForeignMode  bool     `json:"foreign"` // for foreign key
	ViewFields   []string `json:"-"`       // for view
	SearchFields []string `json:"-"`       // for keyword
}

type QueryResult

type QueryResult struct {
	TotalCount int    `json:"total,omitempty"`
	Pos        int    `json:"pos,omitempty"`
	Limit      int    `json:"limit,omitempty"`
	Keyword    string `json:"keyword,omitempty"`
	Items      []any  `json:"items"`
}

type QueryView

type QueryView struct {
	Path    string `json:"path"`
	Method  string `json:"method"`
	Desc    string `json:"desc"`
	Prepare PrepareQuery
}

type UploadResult

type UploadResult struct {
	PublicUrl   string `json:"publicUrl"`
	Thumbnail   string `json:"thumbnail"`
	Path        string `json:"path"`
	Name        string `json:"name"`
	External    bool   `json:"external"`
	StorePath   string `json:"storePath"`
	Dimensions  string `json:"dimensions"`
	Ext         string `json:"ext"`
	Size        int64  `json:"size"`
	ContentType string `json:"contentType"`
}

type WebObject

type WebObject struct {
	Model             any
	Group             string
	Name              string
	Desc              string
	AuthRequired      bool
	Editables         []string
	Filterables       []string
	Orderables        []string
	Searchables       []string
	GetDB             GetDB
	BeforeCreate      BeforeCreateFunc
	BeforeUpdate      BeforeUpdateFunc
	BeforeDelete      BeforeDeleteFunc
	BeforeRender      BeforeRenderFunc
	BeforeQueryRender BeforeQueryRenderFunc

	Views        []QueryView
	AllowMethods int

	PrimaryKeys []WebObjectPrimaryField
	UniqueKeys  []WebObjectPrimaryField
	TableName   string

	// Model type
	ModelElem reflect.Type
	// Map json tag to struct field name. such as:
	// UUID string `json:"id"` => {"id" : "UUID"}
	JsonToFields map[string]string
	// Map json tag to field kind. such as:
	// UUID string `json:"id"` => {"id": string}
	JsonToKinds map[string]reflect.Kind
}

type WebObjectPrimaryField

type WebObjectPrimaryField struct {
	IsPrimary bool
	Name      string
	Kind      reflect.Kind
	JSONName  string
}

Jump to

Keyboard shortcuts

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