代码拉取完成,页面将自动刷新
from peewee import *
database = MySQLDatabase('db_dev_12280', user='money111', password='money_770', host='8.140.162.237', port=3307)
# 数据模型
class BaseModel(Model):
class Meta:
database = database
class DatabaseConnection:
def __enter__(self):
# 建立数据库连接
database.connect()
return database
def __exit__(self, exc_type, exc_val, exc_tb):
# 关闭数据库连接
database.close()
# 数据表结构
class Test(BaseModel):
id = AutoField()
name = CharField(unique=True)
age = IntegerField()
# demo
def demo():
with DatabaseConnection():
# 查询所有
for user in Test.select():
print(f"ID: {user.id}, Name: {user.name}, Age: {user.age}")
print("查询完成")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。