[DB-SIG] Re: module name

Randall Smith randall at tnr.cc
Thu Sep 2 06:14:48 CEST 2004


Mike,

Too late.  We went with dal with dbapi as a subpackage.

To summarize the previous 50 posts on the subject, we're making an 
abstraction layer to hide differences in modules that implement dbapi2. 
  It is a wrapper.  It also adds uniform datetime objects and switchable 
paramstyles.  The wrapper is the first piece of a larger project, hence 
it is a sub-package.  Although, you will only have to import dal to use 
it.  dal will contain a function that returns a wrapped driver.

Here is an example:

import dal
dbmod = dal.wrapdriver('psycopg')
cn = dbmod.connect(database='mydb')
cs = cn.cursor()
params = dbmod.Date(2004, 1, 1)
query = "select * from foo where goo > ?"
cs.execute(query, params)
result = cs.fetchall()

A few things to note.  Even though psycopg uses mx.DateTime, the Python 
datetime.date type was used.  dbmod.Date(2004, 1, 1) generated a Python 
datetime.date object that was translated into an 
mx.Datetime.DateTimeType during cs.execute().  Also note that I used the 
'qmark' paramstyle even though psycopg uses 'pyformat'.  Those are the 
defaults, although both are configurable.

Randall


Mike Dewhirst wrote:
> Could you maybe post the module description in 50 words or less?
> 
> Mike
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig


More information about the DB-SIG mailing list