title: How to map the result from a query to a custom object in sqlalchemy?
body: <p>I'm searching a way to tell sqlalchemy to map a complex query over some tabes to a custom class <code>MyResult</code> instead of the default <code>RowProxy</code> class. Here's a simple working example</p>
  
  <pre><code>'''
  create table foo(id integer, title text);
  create table bar(id integer, foo_id integer, name text);
  insert into foo values(0, 'null');
  insert into foo values(1, 'eins');
  insert into bar values(0,0, 'nullnull');
  insert into bar values(1,0, 'einsnull');
  insert into bar values(2,1, 'zweieins');
  '''
  </code></pre>
  
  <p>and the following code:</p>
  
  <pre><code>from sqlalchemy import *
  from itertools import imap
  
  db = create_engine('sqlite:///test.db')
  metadata = MetaData(db)
  
  class MyResult(object):
      def __init__(self, id, title, name):
          self.id = id
          self.title = title
          self.name = name
  
  foo = Table('foo', metadata, autoload=True)
  bar = Table('bar', metadata, autoload=True)
  
  result = select([foo.c.id, foo.c.title, bar.c.name], foo.c.id == bar.c.foo_id).execute().fetchall()
  </code></pre>
  
  <p>Now I'm looking for a way to tell sqlalchemy to perform a mapping from the result rows to MyResult.</p>
  
  <pre><code>row = result[0]
  print type(row)
  #&lt;class 'sqlalchemy.engine.base.RowProxy'&gt;
  print row.items()
  #[(u'id', 0), (u'title', u'null'), (u'name', u'einsnull')]
  </code></pre>
  
  <p>I know I can do the mapping by hand with something like</p>
  
  <pre><code>my_result = imap(lambda x: MyResult(**x), result)
  </code></pre>
  
  <p>but I have the feeling that this is not the way to handle it in sqlalchemy.</p>