Hi All,

I'm looking for examples of MapperExtensions.

Specifically, I'm looking to implement one that creates new rows when certain attributes of an object changes.

I'm not sure if this is the right approach, so here's some pseudocode of how I'd like to use the end result:

class MyThing(Base,Versioned):

  __tablename__ = 'whatever'

  id = Column(Integer, primary_key=True)
  name = Column(String(80))
  value = Column(Numeric(precision=36, scale=12))

  __versioned__ = ('value',)

  valid_from = Column(DateTime())
  valid_to = Column(DateTime())

>>> x = MyThing(name='foo',value=100)
>>> x.id
None
>>> session.add(x)
>>> session.commit()
>>> x.id, x.name, x.value, x.valid_from, x.valid_to
1, 'foo', 100, 2010-06-29 09:00, None

>>> x.value = 200
>>> session.commit()
>>> x.id, x.name, x.value, x.valid_from, x.valid_to
2, 'foo', 200, 2010-06-29 09:05, None

>>> for thing in session.query(MyThing).all():
...   print x.id, x.name, x.value, x.valid_from, x.valid_to
1, 'foo', 100, 2010-06-29 09:00, 2010-06-29 09:05
2, 'foo', 200, 2010-06-29 09:05, None

Is a MapperExtension the right way to go here?
If so, what's the correct method to change the primary key of x in?

cheers,

Chris

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to