Answer the question
In order to leave comments, you need to log in
Is it worth connecting orm to aiohttp through internal support?
aiohttp, judging by the documentation, supports Gino - this is an orm using the asyncpg driver, based on sqlalchemy.
Now this orm is connected by simple import to my backend:
from aiohttp import web
from gino import Gino
app = web.Application()
db = Gino()
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
fullname = db.Column(db.String)
async def main():
async with db.with_bind('postgresql://localhost/mydb') as engine:
await db.gino.create_all()
await User.create(name='jack', fullname='Jack Jones')
print(await User.query.gino.all())
asyncio.get_event_loop().run_until_complete(main())
# дальше идут вьюхи, роуты и т п - пока всё в одном файле, т.к. мне так удобнее осваивать.
# Позднее всё будет отсортировано по различным модулям
if __name__ == '__main__':
web.run_app(app)
from aiohttp import web
from gino.ext.aiohttp import Gino
db = Gino()
app = web.Application(middlewares=[db])
db.init_app(app)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question