27 lines
744 B
Python
27 lines
744 B
Python
"""创建数据库脚本"""
|
|
import asyncio
|
|
import asyncpg
|
|
|
|
|
|
async def main():
|
|
conn = await asyncpg.connect(
|
|
'postgresql://postgresql:Jchl1528@192.168.110.252:15432/postgres'
|
|
)
|
|
try:
|
|
# 检查数据库是否存在
|
|
exists = await conn.fetchval(
|
|
"SELECT 1 FROM pg_database WHERE datname = 'hospital_performance'"
|
|
)
|
|
if exists:
|
|
print('数据库 hospital_performance 已存在')
|
|
else:
|
|
# 创建数据库
|
|
await conn.execute('CREATE DATABASE hospital_performance')
|
|
print('数据库 hospital_performance 创建成功')
|
|
finally:
|
|
conn.terminate()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|