Documentation
¶
Index ¶
- Constants
- func Count[T any](db *gorm.DB, where ...any) (int, error)
- func Delete[T any](db *gorm.DB, val *T, where ...any) error
- func DeleteByID[T any, E ~int | ~string](db *gorm.DB, id E, where ...any) error
- func DeleteByMap[T any](db *gorm.DB, m map[string]any, where ...any) error
- func ExecuteEdit[T any, V Key](db *gorm.DB, key V, vals map[string]any) (*T, error)
- func ExecuteGet[T any, V Key](db *gorm.DB, key V) (*T, error)
- func ExecuteQuery[T any](db *gorm.DB, form QueryForm, pagination bool) (items []T, count int, err error)
- func FilterEqualScope(filters map[string]any) func(db *gorm.DB) *gorm.DB
- func FilterScope(filters []Filter) func(db *gorm.DB) *gorm.DB
- func Get[T any](db *gorm.DB, val *T, where ...any) (*T, error)
- func GetByID[T any, E ~int | ~string](db *gorm.DB, id E, where ...any) (*T, error)
- func GetByMap[T any](db *gorm.DB, m map[string]any, where ...any) (*T, error)
- func GetColumnNameByField[T any](name string) string
- func GetFieldNameByJsonTag[T any](jsonTag string) string
- func GetPkColumnName[T any]() string
- func GetPkJsonName[T any]() string
- func GetTableName[T any](db *gorm.DB) string
- func HandleCreate[T any](c *gin.Context, db *gorm.DB, onCreate onCreateFunc[T])
- func HandleDelete[T any](c *gin.Context, db *gorm.DB, onDelete onDeleteFunc[T])
- func HandleEdit[T any](c *gin.Context, db *gorm.DB, editables []string, onUpdate onUpdateFunc[T])
- func HandleGet[T any](c *gin.Context, db *gorm.DB, onRender onRenderFunc[T])
- func HandleQuery[T any](c *gin.Context, db *gorm.DB, ctx *QueryOption)
- func KeywordScope(keys map[string]string) func(db *gorm.DB) *gorm.DB
- func List[T any](db *gorm.DB, ctx *ListContext) ([]T, int, error)
- func ListFilter[T any](db *gorm.DB, filter []Filter, where ...any) ([]T, int, error)
- func ListKeyword[T any](db *gorm.DB, keys map[string]string, where ...any) ([]T, int, error)
- func ListModel[T, R any](db *gorm.DB, ctx *ListContext) ([]R, int, error)
- func ListOrder[T any](db *gorm.DB, order string, where ...any) ([]T, int, error)
- func ListPage[T any](db *gorm.DB, page int, pageSize int, where ...any) ([]T, int, error)
- func ListPageKeyword[T any](db *gorm.DB, page, pageSize int, keys map[string]string, where ...any) ([]T, int, error)
- func ListPageKeywordFilterOrder[T any](db *gorm.DB, page, pageSize int, keys map[string]string, filters []Filter, ...) ([]T, int, error)
- func ListPageKeywordFilterOrderModel[T, R any](db *gorm.DB, page, pageSize int, keys map[string]string, filters []Filter, ...) ([]R, int, error)
- func ListPageKeywordOrder[T any](db *gorm.DB, page, pageSize int, keys map[string]string, order string, ...) ([]T, int, error)
- func ListPageOrder[T any](db *gorm.DB, page, pageSize int, order string, where ...any) ([]T, int, error)
- func ListPos[T any](db *gorm.DB, pos, limit int, where ...any) ([]T, int, error)
- func ListPosFilter[T any](db *gorm.DB, pos, limit int, filter []Filter, where ...any) ([]T, int, error)
- func ListPosKeyword[T any](db *gorm.DB, pos, limit int, keys map[string]string, where ...any) ([]T, int, error)
- func ListPosKeywordFilter[T any](db *gorm.DB, pos, limit int, keys map[string]string, filter []Filter, ...) ([]T, int, error)
- func ListPosKeywordFilterOrder[T any](db *gorm.DB, pos, limit int, keys map[string]string, filters []Filter, ...) ([]T, int, error)
- func ListPosKeywordFilterOrderModel[T, R any](db *gorm.DB, pos, limit int, keys map[string]string, filters []Filter, ...) ([]R, int, error)
- func ListPosKeywordOrder[T any](db *gorm.DB, pos, limit int, keys map[string]string, order string, ...) ([]T, int, error)
- func ListPosOrder[T any](db *gorm.DB, pos, limit int, order string, where ...any) ([]T, int, error)
- func New[T any](db *gorm.DB, val *T) (*T, error)
- func PageScope(page, pageSize int) func(db *gorm.DB) *gorm.DB
- func RegisterAdminHandler(r *gin.RouterGroup, m *AdminManager)
- func RegisterObject(r gin.IRoutes, obj *WebObject) error
- func RegisterObjects(r gin.IRoutes, objs []WebObject)
- func RegisterObjectsWithAdmin(r *gin.RouterGroup, objs []WebObject)
- func Update[T any](db *gorm.DB, val *T, where ...any) error
- func UpdateByID[T any, E ~string | ~int](db *gorm.DB, id E, val *T, where ...any) error
- func UpdateFields[T any](db *gorm.DB, model *T, vals map[string]any) error
- func UpdateMapByID[T any, E ~string | ~int](db *gorm.DB, id E, m map[string]any, where ...any) error
- func UpdateSelectByID[T any, E ~string | ~int](db *gorm.DB, id E, selects []string, val *T, where ...any) error
- type AdminManager
- type AdminObject
- type BeforeCreateFunc
- type BeforeDeleteFunc
- type BeforeRenderFunc
- type BeforeUpdateFunc
- type Filter
- type GetDB
- type Key
- type ListContext
- type Order
- type PrepareQuery
- type QueryForm
- type QueryOption
- type QueryResult
- type QueryView
- type TestClient
- func (c *TestClient) Call(method, path string, form any, result any) error
- func (c *TestClient) CallDelete(path string, form, result any) error
- func (c *TestClient) CallGet(path string, form, result any) error
- func (c *TestClient) CallPatch(path string, form, result any) error
- func (c *TestClient) CallPost(path string, form any, result any) error
- func (c *TestClient) CallPut(path string, form, result any) error
- func (c *TestClient) Get(path string) *httptest.ResponseRecorder
- func (c *TestClient) Post(path string, body []byte) *httptest.ResponseRecorder
- func (c *TestClient) SendReq(path string, req *http.Request) *httptest.ResponseRecorder
- type WebObject
Constants ¶
View Source
const ( DefaultQueryLimit = 50 MaxQueryLimit = 150 )
View Source
const ( GET = 1 << 1 CREATE = 1 << 2 EDIT = 1 << 3 DELETE = 1 << 4 QUERY = 1 << 5 BATCH = 1 << 6 )
Request method
Variables ¶
This section is empty.
Functions ¶
func ExecuteEdit ¶
func ExecuteQuery ¶
func ExecuteQuery[T any](db *gorm.DB, form QueryForm, pagination bool) (items []T, count int, err error)
QueryForm: database column format key
func FilterEqualScope ¶
{"name": "mockname", "age": 10 } => name = 'mockname' AND age = 10
func FilterScope ¶
[{"name": "name", op: "=", "value": "mockname" }, {"name": "age", "op": "<", "value": 20 }] => name = 'mockname' AND age < 20
func GetColumnNameByField ¶
func GetFieldNameByJsonTag ¶
func GetPkColumnName ¶
func GetPkJsonName ¶
func HandleEdit ¶
func HandleQuery ¶
TODO: add onRender hook QueryForm: json format key
func KeywordScope ¶
{"name": "mockname", "nick": "mocknick" } => name LIKE '%mockname%' OR nick LIKE '%mocknick%'
func ListFilter ¶
func ListKeyword ¶
func ListPageKeyword ¶
func ListPageKeywordOrder ¶
func ListPageOrder ¶
func ListPosFilter ¶
func ListPosKeyword ¶
func ListPosKeywordFilter ¶
func ListPosKeywordFilterOrderModel ¶
func ListPosKeywordFilterOrderModel[T, R any](db *gorm.DB, pos, limit int, keys map[string]string, filters []Filter, order string, where ...any) ([]R, int, error)
List Model
func ListPosKeywordOrder ¶
func ListPosOrder ¶
func RegisterAdminHandler ¶
func RegisterAdminHandler(r *gin.RouterGroup, m *AdminManager)
RegisterAdmin resolve adminManager & register admin handler
func RegisterObjects ¶
func RegisterObjectsWithAdmin ¶
func RegisterObjectsWithAdmin(r *gin.RouterGroup, objs []WebObject)
RegisterObjectsWithAdmin quickly Register Admin by webobjects
func UpdateByID ¶
func UpdateMapByID ¶
Types ¶
type AdminManager ¶
type AdminManager struct { AdminObjects []AdminObject Names []string }
func (*AdminManager) RegisterObject ¶
func (m *AdminManager) RegisterObject(r *gin.RouterGroup, obj WebObject)
type AdminObject ¶
type BeforeCreateFunc ¶
type BeforeUpdateFunc ¶
type ListContext ¶
type ListContext struct { Pos int Limit int Keywords map[string]string Filters []Filter Order string Where []any }
List Context
type PrepareQuery ¶
type QueryForm ¶
type QueryForm struct { Pagination bool `json:"pagination"` Pos int `json:"pos"` Limit int `json:"limit"` Keyword string `json:"keyword,omitempty"` Filters []Filter `json:"filters,omitempty"` Orders []Order `json:"orders,omitempty"` ViewFields []string `json:"-"` // for view // contains filtered or unexported fields }
type QueryOption ¶
type QueryResult ¶
type QueryResult[T any] struct { Total int `json:"total,omitempty"` Pos int `json:"pos,omitempty"` Limit int `json:"limit,omitempty"` Keyword string `json:"keyword,omitempty"` Items T `json:"items"` }
func QueryObjects ¶
QueryObjects execute query and return data.
type QueryView ¶
type QueryView struct { Name string Method string Prepare PrepareQuery }
type TestClient ¶
type TestClient struct { CookieJar http.CookieJar Scheme string Host string // contains filtered or unexported fields }
func NewTestClient ¶
func NewTestClient(r http.Handler) (c *TestClient)
func (*TestClient) Call ¶
func (c *TestClient) Call(method, path string, form any, result any) error
func (*TestClient) CallDelete ¶
func (c *TestClient) CallDelete(path string, form, result any) error
func (*TestClient) CallPost ¶
func (c *TestClient) CallPost(path string, form any, result any) error
func (*TestClient) Get ¶
func (c *TestClient) Get(path string) *httptest.ResponseRecorder
Get return *httptest.ResponseRecorder
func (*TestClient) Post ¶
func (c *TestClient) Post(path string, body []byte) *httptest.ResponseRecorder
Post return *httptest.ResponseRecorder
func (*TestClient) SendReq ¶
func (c *TestClient) SendReq(path string, req *http.Request) *httptest.ResponseRecorder
type WebObject ¶
type WebObject struct { Model any Group string Name string GetDB GetDB // config // Pagination bool AllowMethods int // for query EditFields []string FilterFields []string OrderFields []string SearchFields []string Views []QueryView // hooks BeforeCreate BeforeCreateFunc BeforeUpdate BeforeUpdateFunc BeforeDelete BeforeDeleteFunc BeforeRender BeforeRenderFunc // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.