crud

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package crud provides a generic CRUD engine for GORM models.

It generates standard list, detail, create, update, and delete endpoints from a GORM model struct, including automatic front-end component generation. Use CRudApiBuild to bootstrap an entire admin resource.

Index

Constants

View Source
const (
	WhereEQ   uint8 = iota + 1 // =
	WhereLike                  // LIKE
	WhereIn                    // IN
	WhereGt                    // >
	WhereLt                    // <
	WhereGe                    // >=
	WhereLe                    // <=
	WhereTst                   // > AND <
	WhereEst                   // >= AND <
	WhereTse                   // > AND <=
	WhereEse                   // >= AND <=
	WhereFs                    // FIND_IN_SET
)

数据筛选自动sql条件

View Source
const (
	ElementComponentInput uint8 = iota + 1 // input
	ElementComponentDatePicker
	ElementComponentDateRangePicker
	ElementComponentDateTimePicker
	ElementComponentDateTimeRangePicker
	ElementComponentSelect
	ElementComponentCascader
)

Element 组件

Variables

This section is empty.

Functions

This section is empty.

Types

type DataOrigin

type DataOrigin interface {
	Page(req request.CRUDRequest) (data []map[string]interface{}, count int64, pageSize int64, err error)
	GetById(req request.CRUDRequest) (data map[string]interface{}, err error)
	UpdateById(req request.CRUDRequest) (id interface{}, err error)
	Create(req request.CRUDRequest) (id interface{}, err error)
	Delete(req request.CRUDRequest) (id interface{}, err error)
}

type ElOption

type ElOption struct {
	Type       uint8         // 对应 Element 组件类型
	SearchType uint8         // 后台搜索的条件类型
	Options    func() string // 筛选框 item
	Props      string        // 筛选框属性设置
}

type Engine

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

实体

func NewEngine

func NewEngine(absolutePath string, opt Options) *Engine

func (*Engine) AddField

func (e *Engine) AddField(filed ...Field) *Engine

func (*Engine) AddMiddleware

func (e *Engine) AddMiddleware(m ...gin.HandlerFunc) *Engine

func (*Engine) Register

func (e *Engine) Register()

func (*Engine) RegisterDeleteHandler

func (e *Engine) RegisterDeleteHandler(relativePath string, handlerFunc gin.HandlerFunc) *Engine

func (*Engine) RegisterGetHandler

func (e *Engine) RegisterGetHandler(relativePath string, handlerFunc gin.HandlerFunc) *Engine

func (*Engine) RegisterPatchHandler

func (e *Engine) RegisterPatchHandler(relativePath string, handlerFunc gin.HandlerFunc) *Engine

func (*Engine) RegisterPostHandler

func (e *Engine) RegisterPostHandler(relativePath string, handlerFunc gin.HandlerFunc) *Engine

type Field

type Field struct {
	Name             string                                           // 展示名
	Column           string                                           // 字段名
	Type             string                                           // 字段类型
	ElOption         ElOption                                         // 对应前端 Element 类型 TODO 实现这里的功能,通过模版渲染switch来完成 表单,列表内容的输出
	TranslateFunc    func() map[string]string                         // 字段翻译函数:返回用来翻译字段的map
	FormatFunc       func(value, originValue interface{}) interface{} // 字段格式化函数
	SortAble         bool                                             // 是否排序字段
	Hide             bool                                             // 是否对外展示
	EditAble         bool                                             // 是否可更新
	DefaultValueFunc func() string                                    // 数据创建时的默认值
}

字段

type Options

type Options struct {
	DbName           string // 指定数据库连接
	TableName        string // 指定表名
	PK               string // 指定主键字段
	SoftDelete       string // 指定软删除字段
	OrderBy          string // 指定默认排序
	HideCreateBtn    bool   // 隐藏创建按钮
	HideDeleteBtn    bool   // 隐藏删除按钮
	HideEditBtn      bool   // 隐藏编辑按钮
	CustomDataOrigin DataOrigin
}

选项参数

Jump to

Keyboard shortcuts

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