新项目 Python 3x PostgreSQL 9x 和 pg8000 1x DBAPI?

发布于 2024-09-16 15:39:41 字数 306 浏览 8 评论 0原文

我正在开始一些新项目,想知道 pg8000 是否被认为是生产项目的不错选择?

显然Python和PostgreSQL都是成熟的产品,但我对pg8000的成熟度和性能都很担心。我的数据库访问会受到影响还是可以接受?

所以,请在回答我的问题时保持一定的自由度。 pg8000准备好了吗?在编写以数据库为中心的程序时,使用 Python DBAPI 2.0 规范进行完全访问是否会遇到问题?

我知道人们总是会问这样的问题,但我确实查看过,但找不到任何与 pg8000 有关的最新信息。显然,考虑到相关技术已经发布的版本,任何超过几个月的答案都不会是最新的。

I'm starting some new projects and want to know if pg8000 is considered a good choice for a production project?

Obviously Python and PostgreSQL are mature products, but I'm concerned about pg8000 both when it comes to maturity and performance. Will my DB access suffer or will it be acceptable?

So, please take some latitude in responding to my question. Is pg8000 ready? Will I have problems using the Python DBAPI 2.0 spec for complete access when writing a db centric program?

I know questions like this get asked all the time, but I did look and could not find anything current relating to pg8000. And obviously any answer beyond a few months would not be current considering the releases that have been committed on the related technologies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-09-23 15:39:41

我认为你应该尝试让你的程序驱动程序“独立”。它应该与任何 PostgreSQL DBAPI 2.0 驱动程序一起使用。唯一的区别在于导入部分和建立数据库连接。这可能看起来像:

use_pgdb = 0
try:
    import pgdb
    use_pgdb = 1
except:
    try:
        import psycopg2
    except:
        raise exceptions.ImportError('No PostgreSQL library, install psycopg2 or PyGres!')
if use_pgdb:
    _CONN = pgdb.connect(connect_string)
else:
    _CONN = psycopg2.connect(dsn)

添加到这个驱动程序“链”pg8000并简单地尝试一下。如果所有驱动程序都能工作并且性能良好,则保留这些驱动程序。如果其中一个驱动程序无法工作或性能不佳,请在代码中对其进行注释并禁用它。对于超过 2 个驱动程序,我会更改示例中的代码并创建某种带有驱动程序和连接功能的字典。

I think your should try to make your program driver "independent". It should work with any PostgreSQL DBAPI 2.0 driver. The only difference will be at import section and at establishing a db connection. This can look like:

use_pgdb = 0
try:
    import pgdb
    use_pgdb = 1
except:
    try:
        import psycopg2
    except:
        raise exceptions.ImportError('No PostgreSQL library, install psycopg2 or PyGres!')
if use_pgdb:
    _CONN = pgdb.connect(connect_string)
else:
    _CONN = psycopg2.connect(dsn)

Add to this "chain" of drivers pg8000 and simply try it. If all drivers will work and performance will be good then leave those drivers. If one of the drivers will not work, or will have poor performance then comment it in your code and disable it. For more than 2 drivers I would change code from example and create some kind of dictionary with driver and connect function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文