Carlos Ribeiro wrote:
> I have right now some code that initializes a few 'bootstrap' objects
> for a system. Right now the database is created by a separate script.
> Each add-on module needs to be run later to save is own objects. This
> causes some problems, as I need to re-run all addo-on modules when a
> single one changes. One of the reasons is that the initialization code
> is simple-minded: it only tries to create the required objects, and it
> does not check if the object already exists, or if it was modified. I
> really don't think that it should be necessary for me to trap all
> calls into try: except : , or to check explicitly for the existence of
> the objects.
>
> My proposal is to add two new classmethods to the SQLObJect class:
>
> 1. The 'overwrite' method checks if the object exists, and overwrites
> it with a new version. It uses the alternate keys to check if the
> object exists. (this is based on the assumption that I can't know the
> ID beforehand). The method signature is:
Some databases have a REPLACE command similar to this. But I think it's
kind of confusing when used generically, because it's not clear what
basis you are using to replace a row. Alternate ID? Which one? What's
authoritative, what's just unique? I think it has to be parameterized,
it can't be a generic class method on all SQLObject classes.
But I can certainly see the use case. Maybe we could add a recipes/ or
contrib/ directory to SQLObject. Like documentation, these could be
based on pages in the Wiki.
--
Ian Bicking / ia...@co... / http://blog.ianbicking.org
|