Django支持异步数据库引擎
我找不到有关Django支持异步数据库引擎的信息。例如,对于PostgreSQL Django,仅支持Psycopg2库,该库完全同步并且不支持任何支持,因为SQLite Django仅支持同步的SQLite3库。因此,我在django中并不是很好,当然我可能会误会,但是如果django asgi不支持异步数据库引擎的django asgi感(我的意思是,那么所有异步代码都会同步)?
第二个问题是,有什么方法可以在Django中使用异步发动机?
I can't find information about django support for asynchronous database engines. For example for postgresql django supports only psycopg2 library, that is completely synchronous and nothing more is supported, for sqlite django supports only sqlite3 library that is synchronous as well. So I'm not well orientiered in django and of course I can be mistaken, but what's the sense of django asgi if it doesn't support asynchronous database engines(I mean, then all the asynchronous code becomes synchronous) ?
And the second question, is there any way to use asynchronous engines in django ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自Django文档
*您是否正在寻找哪种数据库Async支持? *
https://docs.djangoproject.com/en/4.0/4.0/topics/topics/async/
This is from the Django Docs
*Are you looking for what kind of database async support? *
https://docs.djangoproject.com/en/4.0/topics/async/
据我所知,在Django Orm中没有对异步的支持。因此,您应该考虑使用不同的框架或集成不同的ORM,例如Sqlalchemy,
这是他们在文档中所说的:
“我们仍在为Django的ORM和其他部分提供异步支持。您可以期望在将来的版本中看到此内容。目前,您可以使用Sync_to_async()适配器与Django的同步部分进行交互。您还可以集成的一系列异步的python库。”
对于您的第二个问题:配置Django以使用SQLalchemy ,
但我强烈建议您考虑切换开关框架如果您没有很多Django绑定的书面代码。要像 fastapi 或 aiohttp
As far as I know there is no support for async in Django ORM. So you should consider using different framework or integrate different ORM like sqlalchemy
Here is what they say in the doc:
"We’re still working on async support for the ORM and other parts of Django. You can expect to see this in future releases. For now, you can use the sync_to_async() adapter to interact with the sync parts of Django. There is also a whole range of async-native Python libraries that you can integrate with."
For your second question: Configuring Django to use SQLAlchemy
But I would strongly recommend to consider switching framework if you don't have a lot django bonded written code. To something like FastAPI, or aiohttp