[英]SQLAlchemy and django, is it production ready?
Has anyone used SQLAlchemy
in addition to Django
's ORM?除了
Django
的 ORM 之外,还有人使用SQLAlchemy
吗?
I'd like to use Django's ORM for object manipulation and SQLalchemy for complex queries (like those that require left outer joins).我想使用 Django 的 ORM 进行对象操作,使用 SQLalchemy 进行复杂查询(比如那些需要左外连接的查询)。
Is it possible?可能吗?
Note: I'm aware about django-sqlalchemy
but the project doesn't seem to be production ready.注意:我知道
django-sqlalchemy
,但该项目似乎还没有准备好生产。
What I would do,我会做什么,
Define the schema in Django orm, let it write the db via syncdb.在 Django orm 中定义 schema,让它通过 syncdb 写入 db。 You get the admin interface.
您将获得管理界面。
In view1 you need a complex join在 view1 你需要一个复杂的连接
def view1(request):
import sqlalchemy
data = sqlalchemy.complex_join_magic(...)
...
payload = {'data': data, ...}
return render_to_response('template', payload, ...)
I don't think it's good practice to use both.我不认为同时使用两者是一个好习惯。 You should either:
您应该:
Of course, if you need Django's admin, then the first of these approaches is recommended.当然,如果你需要 Django 的管理员,那么推荐第一种方法。
I've done it before and it's fine.我以前做过,很好。 Use the SQLAlchemy feature where it can read in the schema so you don't need to declare your fields twice.
使用 SQLAlchemy 功能,它可以在模式中读取,因此您不需要两次声明您的字段。
You can grab the connection settings from the settings, the only problem is stuff like the different flavours of postgres driver (eg with psyco and without).您可以从设置中获取连接设置,唯一的问题是诸如不同风格的 postgres 驱动程序之类的东西(例如,有和没有 psyco)。
It's worth it as the SQLAlchemy stuff is just so much nicer for stuff like joins.这是值得的,因为 SQLAlchemy 的东西对于连接之类的东西要好得多。
Jacob Kaplan-Moss admitted to typing "import sqlalchemy" from time to time. Jacob Kaplan-Moss 承认不时输入“import sqlalchemy”。 I may write a queryset adapter for sqlalchemy results in the not too distant future.
在不久的将来,我可能会为 sqlalchemy 结果编写一个查询集适配器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.