table

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 27 Imported by: 3

Documentation

Index

Constants

View Source
const MODULE = "table"

Variables

View Source
var Path = "tables"

Functions

func ApiCount

func ApiCount(ctx *gin.Context)

func ApiCreate

func ApiCreate(ctx *gin.Context)

func ApiDelete

func ApiDelete(ctx *gin.Context)

func ApiDetail

func ApiDetail(ctx *gin.Context)

func ApiExport

func ApiExport(ctx *gin.Context)

func ApiImport

func ApiImport(ctx *gin.Context)

func ApiSearch

func ApiSearch(ctx *gin.Context)

func ApiTableCreate

func ApiTableCreate(ctx *gin.Context)

func ApiTableList

func ApiTableList(ctx *gin.Context)

func ApiTableReload

func ApiTableReload(ctx *gin.Context)

func ApiTableRemove

func ApiTableRemove(ctx *gin.Context)

func ApiTableRename

func ApiTableRename(ctx *gin.Context)

func ApiUpdate

func ApiUpdate(ctx *gin.Context)

func ColumnToCondition added in v0.6.19

func ColumnToCondition(f *smart.Column, val string, hasJoin bool) (cond builder.Cond, err error)

func Error

func Error(ctx *gin.Context, err error)

func Fail

func Fail(ctx *gin.Context, err string)

func FormFiles

func FormFiles(ctx *gin.Context) (files []*multipart.FileHeader, err error)

func List

func List(ctx *gin.Context, data any, total int64)

func Load

func Load(path string) error

func OK

func OK(ctx *gin.Context, data any)

func Register

func Register(table *Table)

func RemoveHookValues added in v0.6.0

func RemoveHookValues(name string)

func Scan

func Scan(dir string) error

func SetHookValues added in v0.6.0

func SetHookValues(name string, value any)

func Startup

func Startup() error

func Sync

func Sync(tables []*Table) error

Types

type Document

type Document map[string]any

type Hook added in v0.6.0

type Hook struct {
	BeforeInsert func(doc Document) error
	AfterInsert  func(id any, doc Document) error
	BeforeUpdate func(id any, update Document) error
	AfterUpdate  func(id any, update Document, base Document) error
	BeforeDelete func(id any) error
	AfterDelete  func(id any, doc Document) error

	Scripts *HookScripts `json:"scripts,omitempty"`
}

func (*Hook) Compile added in v0.6.0

func (h *Hook) Compile() error

type HookScripts added in v0.6.0

type HookScripts struct {
	BeforeInsert string `json:"before_insert,omitempty"`
	AfterInsert  string `json:"after_insert,omitempty"`
	BeforeUpdate string `json:"before_update,omitempty"`
	AfterUpdate  string `json:"after_update,omitempty"`
	BeforeDelete string `json:"before_delete,omitempty"`
	AfterDelete  string `json:"after_delete,omitempty"`
}

type Join added in v0.6.8

type Join struct {
	Table        string `json:"table,omitempty"`         //表名
	LocalField   string `json:"local_field,omitempty"`   //主表字段
	ForeignField string `json:"foreign_field,omitempty"` //附表字段(外键)
	Field        string `json:"field,omitempty"`         //取字段 TODO 可以改为数组
	As           string `json:"as,omitempty"`            //赋值
}

type ParamSearch added in v0.6.8

type ParamSearch struct {
	Skip   int            `form:"skip" json:"skip"`     //越过条数
	Limit  int            `form:"limit" json:"limit"`   //限制条数
	Sort   map[string]int `form:"sort" json:"sort"`     //排序 仅支持一个字段
	Filter map[string]any `form:"filter" json:"filter"` //条件
	Joins  []*Join        `form:"joins" json:"joins"`   //联合查询的字段
	Fields []string       `form:"fields" json:"fields"` //要查询的字段
}

type ReplyData

type ReplyData[T any] struct {
	Data  T      `json:"data"`
	Error string `json:"error,omitempty"`
}

type ReplyList

type ReplyList[T any] struct {
	Data  []T    `json:"data"`
	Total int64  `json:"total"`
	Error string `json:"error,omitempty"`
}

type Table

type Table struct {
	Name          string          `json:"name,omitempty"`
	Comment       string          `json:"comment,omitempty"`
	Columns       []*smart.Column `json:"columns,omitempty"`
	Joins         []*Join         `json:"joins,omitempty"`
	DisableInsert bool            `json:"disable_insert,omitempty"`
	DisableUpdate bool            `json:"disable_update,omitempty"`
	DisableDelete bool            `json:"disable_delete,omitempty"`

	//原生钩子
	Hook
	// contains filtered or unexported fields
}

func Get

func Get(name string) (*Table, error)

func (*Table) AddColumn added in v0.6.21

func (t *Table) AddColumn(column *smart.Column)

func (*Table) Column added in v0.6.19

func (t *Table) Column(name string) *smart.Column

func (*Table) Count

func (t *Table) Count(filter map[string]any) (cnt int64, err error)

func (*Table) Create

func (t *Table) Create() error

func (*Table) Delete

func (t *Table) Delete(filter map[string]any) (rows int64, err error)

func (*Table) DeleteById

func (t *Table) DeleteById(id any) (rows int64, err error)

func (*Table) Drop

func (t *Table) Drop() error

func (*Table) Find

func (t *Table) Find(body *ParamSearch) (rows []map[string]any, err error)

func (*Table) Get

func (t *Table) Get(id any, columns []string) (Document, error)

func (*Table) Init added in v0.6.0

func (t *Table) Init() error

func (*Table) Insert

func (t *Table) Insert(values map[string]any) (id any, err error)

func (*Table) Join added in v0.6.9

func (t *Table) Join(body *ParamSearch) (rows []map[string]any, err error)

func (*Table) PrimaryKeys added in v0.6.0

func (t *Table) PrimaryKeys() []*smart.Column

func (*Table) Schema

func (t *Table) Schema() *schemas.Table

func (*Table) Update

func (t *Table) Update(filter map[string]any, values map[string]any) (rows int64, err error)

func (*Table) UpdateById

func (t *Table) UpdateById(id any, values map[string]any) (rows int64, err error)

Jump to

Keyboard shortcuts

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