A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/2550292/purpose-of-sqlalchemy-over-mysqldb below:

python - Purpose of SQLAlchemy over MySQLdb

Asked 15 years, 4 months ago

Viewed 24k times

Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer?

asked Mar 31, 2010 at 3:19

Eric PruittEric Pruitt

1,90333 gold badges2323 silver badges3535 bronze badges

You don't use SQLAlchemy instead of MySQLdb—you use SQLAlchemy to access something like MySQLdb, oursql (another MySQL driver that I hear is nicer and has better performance), the sqlite3 module, psycopg2, or whatever other database driver you are using.

An ORM (like SQLAlchemy) helps abstract away the details of the database you are using. This allows you to keep from the miry details of the database system you're using, avoiding the possibility of errors some times (and introducing the possibility of others), and making porting trivial (at least in theory).

answered Mar 31, 2010 at 3:43

Mike GrahamMike Graham

77k1616 gold badges104104 silver badges131131 bronze badges

2

Easier portability among different DB engines (say that tomorrow you decide you want to move to sqlite, or PostgreSQL, or...), and higher level of abstraction (and thus potentially higher productivity).

Those are some of the good reasons. There are also some bad reasons for using an ORM, such as not wanting to learn SQL, but I suspect SQLAlchemy in particular is not really favored by people for such bad reasons for wanting an ORM rather than bare SQL;-).

answered Mar 31, 2010 at 3:22

Alex MartelliAlex Martelli

886k175175 gold badges1.3k1.3k silver badges1.4k1.4k bronze badges

3

In addition to what Alex said...

  1. "Not wanting to learn SQL" is probably a bad thing. However, if you want to get more people who want to avoid SQL involved as part of the development process, ORMs do a pretty good job at it because it abstracts away "raw SQL," pushing that level of complexity down a notch. One of the elements that has made Django successful is its ability to let "newspaper journalists" maintain a website, rather than software engineers.

  2. One of the limitations of ORMs is that they are not as scalable as using raw SQL. At a previous job, we wanted to get rid of a lot of manual SQL generation and switched to an ORM for ease-of-use (SQLAlchemy, Elixir, etc.), but months later, I ended up having to write raw SQL again to get around the inefficient or high latency queries that were generated by the ORM system.

answered Mar 31, 2010 at 4:55

wescpywescpy

11.2k33 gold badges5858 silver badges5656 bronze badges

4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4