SQLAlchemy还是psycopg2? [英] SQLAlchemy or psycopg2?

查看:491
本文介绍了SQLAlchemy还是psycopg2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个快速且肮脏的脚本,该脚本需要与数据库(PG)交互。

I am writing a quick and dirty script which requires interaction with a database (PG).

该脚本是对现有问题的实用,战术解决方案。但是,我设想该脚本将随着时间的推移而演变成一个更加完善的系统。鉴于它目前正在快速整合(即我没有时间倾注大量文档)的事实,我很想使用psycopg走这条肮脏的路。

The script is a pragmatic, tactical solution to an existing problem. however, I envisage that the script will evolve over time into a more "refined" system. Given the fact that it is currently being put together very quickly (i.e. I don't have the time to pour over huge reams of documentation), I am tempted to go the quick and dirty route, using psycopg.

psycopg2的优点(据我目前所知)是:

The advantages for psycopg2 (as I currently understand it) is that:


  1. 用C编写,因此比sqlAlchemy(用Python编写)更快?

  2. 由于仅使用一个db和一个db(暗示->快速),因此DBAPI上没有抽象层

  3. (目前),我不需要ORM,因此我可以直接执行SQL语句而无需学习新的ORM语法(即轻量级)

缺点:


  1. 我知道我想要一个ORM线

  2. psycopg2是(日期?)-不知道它将保留多长时间

我的对SqlAlchemy的理解(缓慢/解释,肿,陡峭的学习曲线)正确-无论如何我都可以使用sqlA lchemy以粗糙且准备就绪的方式来使用psycopg-即:

Are my perceptions of SqlAlchemy (slow/interpreted, bloated, steep learning curve) true - IS there anyway I can use sqlAlchemy in the "rough and ready" way I want to use psycopg - namely:


  1. 直接执行SQL语句,而无需弄乱ORM层等。

有这样做的例子吗?

推荐答案

SQLAlchemy是一个ORM,psycopg2是一个数据库驱动程序。这些是完全不同的东西:SQLAlchemy 生成 SQL语句,而psycopg2将SQL语句发送到数据库。 SQLAlchemy依赖于psycopg2或其他数据库驱动程序来与数据库进行通信!

SQLAlchemy is a ORM, psycopg2 is a database driver. These are completely different things: SQLAlchemy generates SQL statements and psycopg2 sends SQL statements to the database. SQLAlchemy depends on psycopg2 or other database drivers to communicate with the database!

作为一个相当复杂的软件层,SQLAlchemy确实增加了一些开销,但这也极大地提高了开发速度,至少在您学习了该库之后。 SQLAlchemy是一个出色的库,它将教您整个ORM概念,但是如果您不想生成以SQL语句开头的内容,那么您就不需要SQLAlchemy。

As a rather complex software layer SQLAlchemy does add some overhead but it also is a huge boost to development speed, at least once you learned the library. SQLAlchemy is a excellent library and will teach you the whole ORM concept, but if you don't want to generate SQL statements to begin with then you don't want SQLAlchemy.

这篇关于SQLAlchemy还是psycopg2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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