There are several such methods.
async def list(self, provider:int): await self.database.connect_async() for row in models.accounts.Account.select().where(Account.provider == provider & Account.deleted == False).execute(): yield row self.database.close() I would like to bring the connection and disconnection to the decorator, but since this is a generator, the interior of the decorator will return it immediately.
The base is a peewee pool: database = peewee_asyncext.PooledPostgresqlExtDatabase()
@dbdecor async def list(self, provider:int): return models.accounts.Account.select().where(Account.provider == provider & Account.deleted == False).execute() or
async def list(self, provider:int): return dbdecor(models.accounts.Account.select().where(Account.provider == provider & Account.deleted == False).execute())
(z**2 for z in (x for x in [1,2,3]))Then it is enough that your function and decorator return the generators. - Eugene Denniswith, to make a connection to the database from the methods is appropriate ... usually the connection is prescribed to the database once in the main function (app), see how it is implemented for example here ( github.com/tornadoweb/tornado/blob/master/demos/blog/ blog.py ). - Eugene Dennis