[DB-SIG] How to *you* access your database objects?
Wed, 16 Oct 2002 09:40:48 -0400 (EDT)
On Wed, 16 Oct 2002, Eivind Tagseth wrote:
> * Kevin Jacobs <email@example.com> [021016 12:20]:
> > On Wed, 16 Oct 2002, Eivind Tagseth wrote:
> > > But what do you actually do with the data you retrieve. And how do you
> > > retrieve it?
> > A simple question... a rather long and complex answer.
> > We use the following components:
> > 1) A database row object that supports tuple, dictionary and object-like
> > access. It is implemented without allocating a dictionary per-object
> > using some of the new Python 2.2 (and 2.3) features. See 'dbrow' on
> > http://opensource.theopalgroup.com/
> > for details on a very early version of this concept. Our current
> > version has evolved far beyond that, and is implemented in both Python
> > and as a C extension module, so there is effectively no performance
> > hit compared to returning rows as tuples.
> Great stuff. This fits quite well into my line of thought as well, and
> exchanging my UserDict-based class with db_row was really simple.
> The db_row-generated classes works pretty much like a dictionary
> (i.e. I can to object['attribute']), but not completely. Is there any
> special reason why not all dictionary methods are compatible with
> dictionaries? That is, why _items(), _keys(), _values() and _has_key()
> rather than items(), keys(), values() and has_key()?
That old version of db_row renames the dictionary methods to avoid namespace
collisions with fields named 'keys', 'values', etc. Our new db_row
implementation is restructured as follows:
R = db_row.IRowMetaClass( ('a','b','c') )
row = R( (1,2,3) )
# Dict like access
row['A'] # case-insensitive access
for 'a' in row: ...
# Tuple like access
row[0:2] # returns a tuple
row[:] # returns a tuple
# Object like access (this is different from the older implementation)
row.fields.A # case-insensitive access
If you are interested, I'll spend some time and package our current version
and make it available on opensource.theopalgroup.com. It can be used in two
modes: 1) as portable pure-python or 2) augmented with an optional C
extension module (tested with Python 2.2.1 and 2.2.2 and recent 2.3 CVS
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19 E-mail: firstname.lastname@example.org
Fax: (216) 986-0714 WWW: http://www.theopalgroup.com