Re: [SQLObject] Re: Preparing for 0.6.1
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Luke O. <lu...@me...> - 2004-12-31 08:39:28
|
Quoting Brian Beck <ex...@gm...>: > - Do only methods that are passed the transaction provided by > conn.transaction() take advantage of it? If so, how do you insert new > rows within a transaction? I can only see one way to create a new row, > i.e.: Person(name='Brian'), but no way to pass this a transaction > 'instance' (I tried a few different ways). trans = conn.transaction() ... Person(name='Brian', connection=trans) (To your question, yes, and the constructor/create method takes a connection argument like all the others.) On the topic of 0.6.1 and transactions, how are people dealing with pre-existing objects that need to be updated in a transaction? In my base class I add a method to return a copy of the object in a new transaction: def inConnection(connection): return self.__class__.get(self.id, connection=connection) brian = Person.get(1) ... # use brian for display or whatever trans = conn.transaction() ... # now need to update brian in trans brianForUpdate = brian.inConnection(trans) brianForUpdate.set(...) Although I suppose nearly the same effect could be had by: brian._connection = trans Although, will brian be moved out of the old connection's cache? Be added to the new connection's (transaction's) cache? If I have other references of the cached object, they'll suddenly be in the transaction, right? Seems to me that's why I orginally wrote inConnection to re-instantiate. So how are other people dealing with this situation? I know way way back we talked about a copyToConnection method which did a little more (would create the object in the new connection if it didn't exist in that database say). - Luke P.S. Speaking of local additions to all my SO classes, I have a method getByID that wraps get() in a try-except and returns None if it wasn't found, for code situations where it's less clear to use exceptions: person = Person.get(req.field('id',None)) if not person: person = Person(...) Useful? |