34 lines
1.8 KiB
Markdown
34 lines
1.8 KiB
Markdown
# script_engine 模块
|
||
|
||
逻辑编程(脚本/规则引擎)模块——脚本表 CRUD + 执行/校验接口。
|
||
|
||
## 功能
|
||
|
||
- `script_engine` 脚本表 CRUD:create_script / update_script / delete_script / get_script / list_scripts
|
||
- `execute_script`:按 id 或按 content+script_type 校验后执行
|
||
- `validate_script_api`:仅校验(语法 + 受限语法),不落库不执行
|
||
- 脚本类型:`0`=Python(受限命名空间,禁 import/类/λ/async/await/对象方法调用),`1`=SQL(仅只读 SELECT/SHOW/DESCRIBE/EXPLAIN,禁写语句/多语句)
|
||
|
||
## 数据表
|
||
|
||
`script_engine`:id(str32 PK)、script_name(str100 not null)、script_type(str32 default '0')、content(text not null)、description(str255)、status(str32 default '1')、created_at、updated_at
|
||
索引:idx_script_name、idx_script_type
|
||
编码:script_type→appcodes_kv(parentid='script_type'),status→appcodes_kv(parentid='script_status')
|
||
|
||
## 安装(挂载到宿主应用)
|
||
|
||
1. `pip install .`(或加入宿主 build.sh 模块安装循环)
|
||
2. 宿主应用 `app/{app}.py`:`from script_engine.init import load_script_engine` + `load_script_engine()`(init() 内)
|
||
3. `scripts/load_path.py` 注册 RBAC(显式路径,无通配符)
|
||
4. `build.sh` 四步:安装 xls2ddl → models→DDL → json→CRUD UI → 链接 wwwroot
|
||
|
||
## 集成
|
||
|
||
- 取库名统一 `ServerEnv().get_module_dbname('script_engine')`(.py)/ `get_module_dbname('script_engine')`(.dspy),禁止硬编码 DBNAME
|
||
- REST 接口(wwwroot/api/*.dspy):script_create / script_update / script_delete / script_get / script_list / script_execute / execute_script / script_validate / validate_script
|
||
- 返回统一 `{code, message, field, detail}`;code=0 成功;分页 `data.list` / `data.total`
|
||
|
||
## 依赖
|
||
|
||
无业务依赖;依赖基础包 sqlor / ahserver / appPublic。
|