Open
Conversation
[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() ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this project?
Peewee-AIO makes Peewee ORM really async (and typing support). All peewee methods are implemented.
So we have another nice async ORM library here
Why is it awesome?
There are no so many async ORM are available and Peewee has a quite nice syntax so it's maybe helpful.
There is already peewee-async on the list, but the library doesn't change Peewee behaviour and you need write a lot of more code to use it. Peewee-AIO makes Peewee models really async and users are able to use similar Peewee syntax but in async way.