api2sql基础的能力 #8
@ -14,6 +14,7 @@ import (
 | 
			
		||||
	"git.zhangdeman.cn/zhangdeman/database/abstract"
 | 
			
		||||
	"git.zhangdeman.cn/zhangdeman/database/define"
 | 
			
		||||
	"git.zhangdeman.cn/zhangdeman/wrapper"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@ -39,6 +40,9 @@ func (e *execute) SetDatabaseClientManager(databaseClientManager abstract.IWrapp
 | 
			
		||||
//
 | 
			
		||||
// Date : 20:48 2024/8/21
 | 
			
		||||
func (e *execute) Run(ctx context.Context, inputParam *define.Api2SqlParam) (any, error) {
 | 
			
		||||
	if err := e.formatAndValidateInputParam(inputParam); nil != err {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(inputParam.InputSql) > 0 {
 | 
			
		||||
		// 基于表达式执行
 | 
			
		||||
		return e.Express(ctx, inputParam)
 | 
			
		||||
@ -68,6 +72,17 @@ func (e *execute) Run(ctx context.Context, inputParam *define.Api2SqlParam) (any
 | 
			
		||||
//
 | 
			
		||||
// Date : 20:52 2024/8/21
 | 
			
		||||
func (e *execute) List(ctx context.Context, inputParam *define.Api2SqlParam) (any, error) {
 | 
			
		||||
	replaceTable := map[string]string{
 | 
			
		||||
		"{FIELD_LIST}": "`" + strings.Join(inputParam.ColumnList, "` , `"),
 | 
			
		||||
		"{TABLE}":      inputParam.Table,
 | 
			
		||||
	}
 | 
			
		||||
	sqlTplList := []string{
 | 
			
		||||
		define.SqlSelectBaseTpl,
 | 
			
		||||
	}
 | 
			
		||||
	if len(inputParam.ValueList) > 0 {
 | 
			
		||||
		// where 条件
 | 
			
		||||
		sqlTplList = append(sqlTplList, define.SqlWhereTpl)
 | 
			
		||||
	}
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ type Api2SqlParam struct {
 | 
			
		||||
	SplitField        string               `json:"split_field"`         // 分表字段, 仅分表时有效, 分表字段要求在 ValueList 必须存在
 | 
			
		||||
	SplitStrategy     string               `json:"split_strategy"`      // 分表策略, 仅分表时有效, 支持注册自动以策略
 | 
			
		||||
	SqlType           string               `json:"sql_type"`            // sql语句类型 : detail - 查询详情 list - 查询列表  count - 查询数量 update - 更新 insert - 插入 delete - 删除
 | 
			
		||||
	ColumnList        []string             `json:"column_list"`         // 仅针对 select / detail 有效, 查询的字段列表
 | 
			
		||||
	ColumnTable       map[string]string    `json:"column_list"`         // 仅针对 select / detail 有效, 查询的字段列表, 字段名 => 字段别名, 不设置, 则以字段名输出
 | 
			
		||||
	Limit             int64                `json:"limit"`               // 操作数据量
 | 
			
		||||
	Offset            int64                `json:"offset"`              // 操作偏移量
 | 
			
		||||
	ForceNoLimit      bool                 `json:"force_no_limit"`      // 强制允许不限制 : 正常操作 select / delete / update 均需要指定本次操作数据量, 如果确定不限制, 此参数设置为 `true` , sqlType = list , 且 ForceNoLimit = true 时,  WithCount 参数无效
 | 
			
		||||
@ -52,6 +52,7 @@ type Api2SqlParam struct {
 | 
			
		||||
type Api2SqlParamValue struct {
 | 
			
		||||
	Column   string `json:"column"`  // 表字段
 | 
			
		||||
	Value    any    `json:"value"`   // 数据字段的值
 | 
			
		||||
	Operate  string `json:"operate"` // 操作符 : Equal , NotEqual , In , NotIn , Like, NotLike
 | 
			
		||||
	Alias    string `json:"alias"`   // 字段对外输出的名字, 不配置, 默认 与 Field 一致, 仅查询语句生效
 | 
			
		||||
	Default  any    `json:"-"`       // 默认值 TODO : 配置默认值生成策略
 | 
			
		||||
	DataMask any    `json:"-"`       // 数据脱敏策略
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user