19 lines
575 B
Python
19 lines
575 B
Python
# init/script.py
|
|
import json
|
|
from sqlor.dbpools import DBPools
|
|
from ahserver.serverenv import ServerEnv
|
|
|
|
async def init_db():
|
|
db = DBPools()
|
|
env = ServerEnv()
|
|
dbname = env.get_module_dbname()
|
|
async with db.sqlorContext(dbname) as sor:
|
|
# 这里假设表已由迁移工具建立;这个脚本负责导入初始数据
|
|
data = json.load(open('init/data.json','r',encoding='utf8'))
|
|
for table, rows in data.items():
|
|
for r in rows:
|
|
# 注意字段类型转换
|
|
await sor.C(table, r)
|
|
return True
|
|
|