[PEAK] SQL Object-relational Mapper

Erik Rose psucorp at grinchcentral.com
Thu May 19 16:06:47 EDT 2005


On May 2, 2005, at 5:20 PM, Ulrich Eck wrote:
> Am Montag, den 02.05.2005, 12:20 -0700 schrieb John Landahl:
>> Ulrich, if you're listening, any objections to me putting an updated  
>> version of your code on PeakPlace?
>
> go ahead, if what's in my cvs at:
> http://cvs.net-labs.de/cgi-bin/viewcvs.cgi/libs/nll/src/nll/database/ 
> sqldm/datamanager.py isn't working or not uptodate. i also have no  
> objection against taking it out of nll and package it with some docs  
> or the like.

I've posted a heavily revised version of Ulrich's code at  
http://peak.telecommunity.com/DevCenter/SqlDm, and I'd love to hear  
comments about the API changes I've wrought. (There's a big, fat  
docstring at the top. If it's unclear, please complain. Regardless, I  
plan to have a public svn and Trac set up soon so you can read the  
detailed changelogs, commit, file tickets, and have a good time.)

Major changes:
  * Updated for compatibility with the latest PEAK
  * Added compatibility with SQL Server and similar DB's which don't  
support sequences
  * Renamed several API-exposed variables for brevity and maybe clarity  
(feedback, please)
  * Added supports for fields which should be read by the DM but not  
written (like DB-maintained timestamps and sequences)
  * Made it work with Python DB API modules that use the pyformat  
paramstyle (like psycopg).

If you want to use the autoIncrementedField feature, you'll need to  
stick a getLastAutoincrementSql() method in your PEAK DB adaptor. It  
looks and behaves like this, which is from my MS SQL Server adapter  
(which I'll publish soon):

def getLastAutoincrementSql(self):
	"""Return the SQL that yields the last value the DB inserted in an  
auto_increment or identity-style column. To avoid race conditions,  
consider only inserts made by this connection (most DB's handle this  
for you).
	
	In DB's (like Postgres) which don't have a function like this and  
which do support sequences, you should probably use getSequenceValue()  
instead, which is more flexible anyway.
	"""
	return 'SELECT @@IDENTITY'

I probably won't be able to make earthshattering API changes until I  
get the current release of my (other) project out the door, but I will  
gratefully collect them!

Cheers,
Erik




More information about the PEAK mailing list