title: How can I combine the awesomness of SQLAlchemy and EAV DB schemas?
body: <p>I've been doing some work with Pylons recently and quite like the SQLAlchemy model for database interaction. There's one section of my website though which I think could benefit from an EAV schema.</p>
  
  <p>Using this as my table example:</p>
  
  <pre><code>id | userid | type   | value
  ---+--------+--------|------------
  1  |  1     |  phone | 111 111 111
  ---+--------+--------|------------
  2  |  1     |  age   | 40
  </code></pre>
  
  <p>I can manually run queries like the following to extract and update data:</p>
  
  <pre><code>SELECT value FROM table WHERE userid=1 AND type='phone'
  UPDATE table SET value=41 WHERE userid=1 AND type='age'
  </code></pre>
  
  <p>That's easy and works... But manually constructing queries is not my preferred approach. I want to use SQLAlchemy to create my table model and let it do all the leg work.</p>
  
  <p>If I were to use a standard schema where each <code>type</code> had it's own column, I could do the following:</p>
  
  <pre><code>class People(Base):
  
     __tablename__ = 'people'
  
     id      = Column(Integer, primary_key=True)
     userid  = Column(Integer, ForeignKey('users.id'))
     phone   = Column(Unicode(40))
     age     = Column(Integer)
  </code></pre>
  
  <p>Then I could pull out the data using:</p>
  
  <pre><code>data = Session.query(People).filter_by(id=1).first()
  print data.age
  </code></pre>
  
  <p>I want to be able to do the same for my EAV schema. So basically, I need a way to extend SQLAlchemy and tell it that when I call <code>data.age</code> that in fact means, I want <code>SELECT value FROM table WHERE id=1 AND type='age'</code>.</p>
  
  <p>Is this doable? Or will I be forced to clutter my code with manually issued queries?</p>