[SQLObject] SQLObject ways of doing things.....
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <po...@nl...> - 2003-11-16 18:40:05
|
I'm looking at using SQLObject as a replacement for a similar structure (no=
w a little untidy) in an existing database system. I've run into the follow=
ing points and would appreciate comments -- there may be ways of doing this=
with SQLObject that I've overlooked, or these may be things that could be =
useful additional features. The basic structure is a system-wide sub-class =
of SQLObject, which is in turn subclassed for each database table.
* Hooks for generic column-level override of _set_ and _get_ -- something l=
ike a "beforeWrite" function that can be overridden:
def beforeWrite(self, columnName, value)
code to produce newValue
self._set_columnName(newValue)
similar for afterRead.
Reason: the existing system has quite a lot of logic for this type of stuff=
in the central class based on the column name and/or type. To write out in=
dividual overrides for each column in each derived class would involve a lo=
t of decentralised code.
* Update control. The existing system passes Mysql timestamp (which are aut=
omatically updated on every database update) columns around to avoid update=
leapfrogging (updated by another user) -- the generated sql is always of t=
ype: =
update x set a=3Db where id=3Dy and lastupdated=3D20030101010101
passing the cursor response back as basis for a confirmation or warning to =
the user.
Is there an easy way to do this in SQLObject, or could it be put in (perhap=
s via _updatecontrolfield and _updatecontrolvalue variables)?
* A generic afterUpdate function that can be overridden -- called each time=
something is changed in the database (used to tidy up non-column variables=
, issue a self.expire() to force re-lookup of column values, getting the ne=
w timestamp for any further updates, etc.).
|