API 方法参考
VEF Framework 预置 API 的完整方法参考。
查询 API
FindOneApi
查询单条记录。
go
apis.NewFindOneApi[M, S]() FindOneApi[M, S]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithSelect(columns ...string) | 指定返回字段 |
WithCondition(fn func(*Query[M]) *Query[M]) | 添加查询条件 |
WithPreload(relations ...string) | 预加载关联 |
WithProcessor(fn func(M) M) | 结果处理器 |
FindAllApi
查询所有记录(无分页)。
go
apis.NewFindAllApi[M, S]() FindAllApi[M, S]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithSelect(columns ...string) | 指定返回字段 |
WithCondition(fn func(*Query[M]) *Query[M]) | 添加查询条件 |
WithOrderBy(order string) | 设置排序 |
WithPreload(relations ...string) | 预加载关联 |
WithProcessor(fn func([]M) []M) | 结果处理器 |
FindPageApi
分页查询。
go
apis.NewFindPageApi[M, S]() FindPageApi[M, S]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithSelect(columns ...string) | 指定返回字段 |
WithCondition(fn func(*Query[M]) *Query[M]) | 添加查询条件 |
WithOrderBy(order string) | 设置排序 |
WithPreload(relations ...string) | 预加载关联 |
WithProcessor(fn func([]M) []M) | 结果处理器 |
WithDefaultPageSize(size int) | 默认分页大小 |
WithMaxPageSize(size int) | 最大分页大小 |
WithQueryPart(part *QueryPart[M]) | 设置查询配置 |
WithDynamicCondition(fn DynamicConditionFunc) | 动态条件 |
WithDynamicSelect(fn DynamicSelectFunc) | 动态字段选择 |
FindTreeApi
树形结构查询。
go
apis.NewFindTreeApi[M, S](builder TreeBuilder[M]) FindTreeApi[M, S]| 方法 | 说明 |
|---|---|
WithIdColumn(column string) | 设置 ID 列名 |
WithParentIdColumn(column string) | 设置父 ID 列名 |
WithRootCondition(fn func(*Query[M]) *Query[M]) | 根节点条件 |
WithLazyLoad(lazy bool) | 启用懒加载 |
FindOptionsApi
选项列表查询。
go
apis.NewFindOptionsApi[M, S]() FindOptionsApi[M, S]| 方法 | 说明 |
|---|---|
WithDefaultColumnMapping(mapping *DataOptionColumnMapping) | 设置列映射 |
WithExtraColumns(columns ...string) | 额外返回列 |
写入 API
CreateApi
创建单条记录。
go
apis.NewCreateApi[M, P]() CreateApi[M, P]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithValidator(fn ValidatorFunc[P]) | 自定义验证器 |
WithTransformer(fn TransformerFunc[M, P]) | 数据转换器 |
WithHook(hookType, fn HookFunc) | 添加钩子 |
WithOmitColumns(columns ...string) | 忽略的列 |
WithSelectColumns(columns ...string) | 只保存的列 |
UpdateApi
更新单条记录。
go
apis.NewUpdateApi[M, P]() UpdateApi[M, P]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithValidator(fn ValidatorFunc[P]) | 自定义验证器 |
WithTransformer(fn TransformerFunc[M, P]) | 数据转换器 |
WithHook(hookType, fn HookFunc) | 添加钩子 |
WithOmitColumns(columns ...string) | 忽略的列 |
WithSelectColumns(columns ...string) | 只更新的列 |
DeleteApi
删除单条记录。
go
apis.NewDeleteApi[M]() DeleteApi[M]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithHook(hookType, fn HookFunc) | 添加钩子 |
WithSoftDelete(soft bool) | 软删除 |
批量 API
CreateManyApi
批量创建。
go
apis.NewCreateManyApi[M, P]() CreateManyApi[M, P]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithBatchSize(size int) | 批量大小 |
WithValidator(fn ValidatorFunc[P]) | 自定义验证器 |
UpdateManyApi
批量更新。
go
apis.NewUpdateManyApi[M, P]() UpdateManyApi[M, P]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
DeleteManyApi
批量删除。
go
apis.NewDeleteManyApi[M]() DeleteManyApi[M]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
导入导出 API
ImportApi
从 Excel/CSV 导入。
go
apis.NewImportApi[M, P]() ImportApi[M, P]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithColumnMapping(mapping map[string]string) | 列映射 |
WithValidator(fn ValidatorFunc[P]) | 自定义验证器 |
WithBatchSize(size int) | 批量大小 |
ExportApi
导出到 Excel/CSV。
go
apis.NewExportApi[M, S]() ExportApi[M, S]| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithDataScope(scope DataScope) | 设置数据范围 |
WithDefaultFormat(format string) | 默认格式 |
WithFilenameBuilder(fn FilenameBuilderFunc) | 文件名生成器 |
WithColumnMapping(mapping map[string]string) | 列映射 |
WithMaxRows(max int) | 最大行数 |
通用方法
所有 API 都支持以下方法:
| 方法 | 说明 |
|---|---|
WithPermission(token string) | 设置权限令牌 |
WithSkipAuth(skip bool) | 跳过认证 |
WithHook(hookType, fn HookFunc) | 添加钩子 |
钩子类型
| 类型 | 说明 | 适用 API |
|---|---|---|
BeforeCreate | 创建前 | CreateApi, CreateManyApi |
AfterCreate | 创建后 | CreateApi, CreateManyApi |
BeforeUpdate | 更新前 | UpdateApi, UpdateManyApi |
AfterUpdate | 更新后 | UpdateApi, UpdateManyApi |
BeforeDelete | 删除前 | DeleteApi, DeleteManyApi |
AfterDelete | 删除后 | DeleteApi, DeleteManyApi |
BeforeQuery | 查询前 | FindOneApi, FindAllApi, FindPageApi |
AfterQuery | 查询后 | FindOneApi, FindAllApi, FindPageApi |