使用GINO和Pony ORM进行异步事务处理
在现代的Python开发中,处理数据库事务是一个常见的需求。GINO和Pony ORM是两个强大的工具,可用于实现异步数据库事务。本文将详细介绍如何使用这两个ORM进行CRUD操作、查询构建以及数据库连接的设置。
1. 使用GINO进行异步事务
1.1 实现CRUD事务
我们以 TrainerRepository 类为例,它用于管理训练师的资料。以下是该类中实现的各种CRUD方法:
from models.data.gino_models import Profile_Members, Profile_Trainers, Gym_Class
from datetime import date, time
from typing import List, Dict, Any
class TrainerRepository:
async def insert_trainer(self, details:Dict[str, Any]) -> bool:
try:
await Profile_Trainers.create(**details)
except Exception as e:
print(e)
return False
return True
async def update_trainer(self, id:int, details:Dict[str, Any])
超级会员免费看
订阅专栏 解锁全文
43

被折叠的 条评论
为什么被折叠?



