Python有什么可行的数据库抽象层 [英] What are the viable database abstraction layers for Python

查看:453
本文介绍了Python有什么可行的数据库抽象层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始参与一个开源项目 Gramps ,它正在探索将其后端从BSDDB切换到关系数据库。 SQLite或MySQL,我们还没有完全决定,甚至可能尝试在一些有限的能力。我是一个专业的开发人员,但我是新的python所以我不熟悉当前选择的工具/库。我的任务是研究DB抽象层。 目前有一个维基讨论来比较它们。对象关系映射器可能很好,但不是绝对必要的。虽然我知道这通常是DB抽象层的同义词。



现在列表包括:



CouchDB
我还没有研究过这个。 / p>

DB-API
这似乎是一个标准的python api和每个db创建自己的模块使用它。即使BSDDB似乎有一个写,但我还没有完全探索它。是可互换的模块?



SQLAlchemy
这似乎是最流行的现在吗?但我对python世界的曝光非常有限。



SQLObject
我还没有研究这个。



那么,关于python的数据库抽象层,人们的看法和建议是什么?

解决方案

仔细查看SQLAlchemy。



您可以使用SQLite进行测试和开发。 / p>

您可以使用MySQL进行生产,基本上不会对您的应用程序进行任何更改。



,同时广泛遵守,具有足够的灵活性,(1)你没有绝缘SQL底层RDBMS的变化和(2)仍然有DB驱动程序特定的功能,很难隐藏。



另一个好的ORM层是ORM,它是 Django



使用ORM图层(SQLAlchemy或SQLObject)优先使用ORM图层(SQLAlchemy或SQLObject),而不使用Django ORM的其他部分。 DB-API。



为什么?你的模型应该是一个坚实,清晰,周到的OO模型。关系映射应该在对象模型之后位于第二。 SQLAlchemy使这是一个合理的方法。



DB抽象层将在正常的事件过程中发生。事实上,由于DB-API(由SQLAlchemy使用),您提供了两个抽象层:ORM和DB-API。


I'm starting to get involved in an open source project Gramps which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capacity. I'm a professional developer but I'm new to python so I'm not that familiar with the current selection of tools/libraries. I've been tasked with researching DB Abstraction Layers. There is currently a wiki discussion going on to compare them. An object relational mapper might be nice but isn't absolutely necessary. though I know that is usually synonymous with a DB Abstraction Layer. If an ORM is included ad hock queries have to be available without to much wrestling.

Right now the list includes:

CouchDB I haven't yet looked into this.

DB-API this seems to be a standard python api and each db creates their own module that uses it. Even BSDDB seems to have one written but I haven't fully explored it. are the modules interchangeable?

SQLAlchemy This seems to be the most popular right now? but I have very limited exposure to the python world.

SQLObject I haven't yet looked into this.

So what are peoples views and suggestions on database abstraction layers for python?

解决方案

Look very closely at SQLAlchemy.

You can test and develop with SQLite.

You can go into production with MySQL -- making essentially no changes to your applications.

The DB-API, while widely adhered-to, has enough flexibility that (1) you aren't insulated from SQL variation in the underlying RDBMS and (2) there are still DB driver-specific features that are hard to hide.

Another good ORM layer is the ORM that's part of Django. You can (with a little effort) use just the Django ORM without using the rest of the Django web framework.

Use an ORM Layer (SQLAlchemy or SQLObject) in preference to DB-API.

Why? Your model should be a solid, clear, well-thought-out OO model. The relational mapping should come second after the object model. SQLAlchemy makes this a reasonable approach.

A "DB Abstraction Layer" will happen in the normal course of events. Indeed, because of DB-API (as used by SQLAlchemy) you gave two abstraction layers: ORM and DB-API.

这篇关于Python有什么可行的数据库抽象层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆