Object Database (ODBMS) for Python

Patrick K. O'Brien pobrien at orbtech.com
Thu Aug 28 21:26:41 EDT 2003


pobrien at orbtech.com (Patrick K. O'Brien) writes:

> pobrien at orbtech.com (Patrick K. O'Brien) writes:
> 
> > I hope that helps demonstrate some of what it can do.
> 
> I forgot to show a cool feature:

Here's another:

>>> u1.name
'Bob'
>>> u1.name = 'Joe'
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "/home/pobrien/Code/pypersyst/entity/entity.py", line 94, in __setattr__
    raise AttributeError, 'Modifications can only be made by transactions'
AttributeError: Modifications can only be made by transactions

So, let's use a transaction:

>>> t = tx.Update(u1, name='Joe')
>>> db.execute(t)
<twistedcred.schema.cred.User object at 0x8884634>
>>> u1.name
'Joe'
>>> 

Of course, nobody is perfect.  So what happens when we send a bad
transaction:

>>> t = tx.Update(u1, foo='Joe')
>>> db.execute(t)
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "/home/pobrien/Code/pypersyst/database.py", line 27, in execute
    return self._engine.execute(transaction)
  File "/home/pobrien/Code/pypersyst/engine/engine.py", line 75, in execute
    return transaction.execute(self._root)
  File "/home/pobrien/Code/pypersyst/entity/transaction.py", line 76, in execute
    return root[self.classname]._update(self.instance, **self.attrs)
  File "/home/pobrien/Code/pypersyst/entity/extent.py", line 312, in _update
    self._validate(instance, combined)
  File "/home/pobrien/Code/pypersyst/entity/extent.py", line 324, in _validate
    instance._validate(attrs)
  File "/home/pobrien/Code/pypersyst/entity/entity.py", line 157, in _validate
    raise error.InvalidAttribute, '%r is not an attribute' % name
InvalidAttribute: 'foo' is not an attribute
>>> 

Can you tell I've been having some fun with this?  ;-)

-- 
Patrick K. O'Brien
Orbtech      http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------




More information about the Python-list mailing list