2525from backend .database .db import async_db_session , create_tables , drop_tables
2626from backend .database .redis import redis_client
2727from backend .plugin .tools import get_plugin_sql , get_plugins
28- from backend .utils ._await import run_await
2928from backend .utils .console import console
3029from backend .utils .file_ops import install_git_plugin , install_zip_plugin , parse_sql_script
3130from backend .utils .import_parse import import_module_cached
@@ -252,17 +251,20 @@ async def import_table(
252251 obj = ImportParam (app = app , table_schema = table_schema , table_name = table_name )
253252 async with async_db_session .begin () as db :
254253 await gen_service .import_business_and_model (db = db , obj = obj )
254+ console .log ('代码生成业务和模型列导入成功' , style = 'bold green' )
255+ console .log ('\n 快试试 [bold cyan]fba codegen[/bold cyan] 生成代码吧~' )
255256 except Exception as e :
256257 raise cappa .Exit (e .msg if isinstance (e , BaseExceptionError ) else str (e ), code = 1 )
257258
258259
259- def generate () -> None :
260+ async def generate () -> None :
260261 from backend .plugin .code_generator .service .business_service import gen_business_service
261262 from backend .plugin .code_generator .service .code_service import gen_service
262263
263264 try :
264265 ids = []
265- results = run_await (gen_business_service .get_all )()
266+ async with async_db_session () as db :
267+ results = await gen_business_service .get_all (db = db )
266268
267269 if not results :
268270 raise cappa .Exit ('[red]暂无可用的代码生成业务!请先通过 import 命令导入![/]' )
@@ -285,12 +287,13 @@ def generate() -> None:
285287 console .print (table )
286288 business = IntPrompt .ask ('请从中选择一个业务编号' , choices = [str (_id ) for _id in ids ])
287289
288- gen_path = run_await (gen_service .generate )(pk = business )
290+ async with async_db_session .begin () as db :
291+ gen_path = await gen_service .generate (db = db , pk = business )
289292 except Exception as e :
290293 raise cappa .Exit (e .msg if isinstance (e , BaseExceptionError ) else str (e ), code = 1 )
291294
292- console .print ('\n 代码已生成完毕 ' , style = 'bold green' )
293- console .print (Text ('\n 详情请查看:' ), Text (gen_path , style = 'bold magenta' ))
295+ console .print ('\n 代码已生成完成 ' , style = 'bold green' )
296+ console .print (Text ('\n 详情请查看:' ), Text (str ( gen_path ) , style = 'bold magenta' ))
294297
295298
296299@cappa .command (help = '初始化 fba 项目' , default_long = True )
@@ -439,8 +442,8 @@ def __post_init__(self) -> None:
439442 except ImportError :
440443 raise cappa .Exit ('代码生成插件不存在,请先安装此插件' )
441444
442- def __call__ (self ) -> None :
443- generate ()
445+ async def __call__ (self ) -> None :
446+ await generate ()
444447
445448
446449@cappa .command (help = '一个高效的 fba 命令行界面' , default_long = True )
0 commit comments