"Correct" db adapter

Diez B. Roggisch deets at nospam.web.de
Wed Jan 31 19:11:57 CET 2007


king kikapu wrote:

> Thanks for the replies.
> 
> I think i do not need something like ORM, but just a db-module that i
> can "work" the database with it.
> I just want to know if pyodbc is the "correct" solution to do so or if
> it is another db-module that is more
> usefull for this job.

I think you've got something wrong. There is no such thing as a generic
DB-Adapter, except maybe from the mxODBC which pushes the abstraction to
the ODBC-layer.

If your app is DB-API2.0-compatible, you should be able to more or less just
use your code with different adapters. There are several ways to accomplish
a configurable way, but in the end it boils down to someting like this:

if is_postgres:
  import psycopg2 as db
if is_mysql:
  import MySQLdb as db

Then db can be used to connect and query the db. A thin layer on top of that
should maybe be written to cover different parameter-styles, but that
shouldn't be too hard.

Diez



More information about the Python-list mailing list