From 99494aa0d198782bdc8f02de464779ff7a38062a Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Sat, 25 Mar 2023 12:10:18 +0300 Subject: [PATCH] Added peewee-aio to Database Drivers [Peewee-AIO](https://github.com/klen/peewee-aio) makes Peewee ORM really async (and typing support). All peewee methods are implemented. So we have another nice async ORM library here ```python import peewee from peewee_aio import Manager, AIOModel, fields manager = Manager('aiosqlite:///:memory:') @manager.register class Role(AIOModel): # Pay attention that we are using fields from Peewee-AIO for better typing support id = fields.AutoField() name = fields.CharField() @manager.register class User(AIOModel): # Pay attention that we are using fields from Peewee-AIO for better typing support id = fields.AutoField() name = fields.CharField() role = fields.ForeignKeyField(Role) async def handler(): # Initialize the database's pool (optional) async with manager: # Acquire a connection async with manager.connection(): # Create the tables in database await Role.create_table() await User.create_table() # Create a record role = await Role.create(name='user') assert role assert role.id # role.id contains correct string type user = await User.create(name="Andrey", role=role) assert user assert user.id role = await user.role # Load role from DB using the foreign key assert role # role has a correct Role Type # Iterate through records async for user in User.select(User, Role).join(Role): assert user # user has a corrent User Type assert user.id role = await user.role # No DB query here, because the fk is preloaded # Change records user.name = "Dmitry" await user.save() # Update records await User.update({"name": "Anonimous"}).where(User.id == user.id) # Delete records await User.delete().where(User.id == user.id) # Drop the tables in database await User.drop_table() await Role.drop_table() ``` --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f3e3beb..4323817 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Find some of those *awesome* packages here and if you are missing one we count o * [Prisma Client Python](https://github.com/RobertCraigie/prisma-client-py) - An auto-generated, fully type safe ORM powered by Pydantic and tailored specifically for your schema - supports SQLite, PostgreSQL, MySQL, MongoDB, MariaDB and more. * [Piccolo](https://github.com/piccolo-orm/piccolo) - An ORM / query builder which can work in async and sync modes, with a nice admin GUI, and ASGI middleware. * [Beanie](https://beanie-odm.dev) - An async MongoDB ODM built on [motor](https://github.com/mongodb/motor) and [Pydantic](https://pydantic-docs.helpmanual.io). +* [peewee-aio](https://github.com/klen/peewee-aio) - Async ORM based on [Peewee ORM](https://github.com/coleifer/peewee) ## Networking