[Sqlalchemy-commits] [5008] sqlalchemy/trunk: - The RowTuple object returned by Query(*cols) now
Brought to you by:
zzzeek
From: <co...@sq...> - 2008-08-05 20:15:33
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[5008] sqlalchemy/trunk: - The RowTuple object returned by Query(*cols) now</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5008</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2008-08-05 16:15:28 -0400 (Tue, 05 Aug 2008)</dd> </dl> <h3>Log Message</h3> <pre>- The RowTuple object returned by Query(*cols) now features keynames which prefer mapped attribute names over column keys, column keys over column names, i.e. Query(Class.foo, Class.bar) will have names "foo" and "bar" even if those are not the names of the underlying Column objects. Direct Column objects such as Query(table.c.col) will return the "key" attribute of the Column.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunkVERSION">sqlalchemy/trunk/VERSION</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyormquerypy">sqlalchemy/trunk/lib/sqlalchemy/orm/query.py</a></li> <li><a href="#sqlalchemytrunktestorminheritancequerypy">sqlalchemy/trunk/test/orm/inheritance/query.py</a></li> <li><a href="#sqlalchemytrunktestorminheritancesinglepy">sqlalchemy/trunk/test/orm/inheritance/single.py</a></li> <li><a href="#sqlalchemytrunktestormquerypy">sqlalchemy/trunk/test/orm/query.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/CHANGES 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -3,6 +3,20 @@ </span><span class="cx"> ======= </span><span class="cx"> CHANGES </span><span class="cx"> ======= </span><ins>+0.5beta4 +======== + +- orm + - The RowTuple object returned by Query(*cols) now + features keynames which prefer mapped attribute + names over column keys, column keys over + column names, i.e. + Query(Class.foo, Class.bar) will have names + "foo" and "bar" even if those are not the names + of the underlying Column objects. Direct + Column objects such as Query(table.c.col) will + return the "key" attribute of the Column. + </ins><span class="cx"> 0.5beta3 </span><span class="cx"> ======== </span><span class="cx"> - 0.5beta3 includes all bugfixes listed under release </span></span></pre></div> <a id="sqlalchemytrunkVERSION"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/VERSION (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/VERSION 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/VERSION 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -1 +1 @@ </span><del>-0.5.0beta3 </del><ins>+0.5.0beta4 </ins></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyormquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/orm/query.py (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/orm/query.py 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/lib/sqlalchemy/orm/query.py 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -1611,11 +1611,15 @@ </span><span class="cx"> </span><span class="cx"> if isinstance(column, basestring): </span><span class="cx"> column = sql.literal_column(column) </span><ins>+ self._result_label = column.name </ins><span class="cx"> elif isinstance(column, (attributes.QueryableAttribute, mapper.Mapper._CompileOnAttr)): </span><ins>+ self._result_label = column.impl.key </ins><span class="cx"> column = column.__clause_element__() </span><span class="cx"> elif not isinstance(column, sql.ColumnElement): </span><span class="cx"> raise sa_exc.InvalidRequestError("Invalid column expression '%r'" % column) </span><del>- </del><ins>+ else: + self._result_label = getattr(column, 'key', None) + </ins><span class="cx"> if not hasattr(column, '_label'): </span><span class="cx"> column = column.label(None) </span><span class="cx"> </span><span class="lines">@@ -1656,7 +1660,7 @@ </span><span class="cx"> def proc(context, row): </span><span class="cx"> return row[column] </span><span class="cx"> </span><del>- return (proc, getattr(column, 'name', None)) </del><ins>+ return (proc, self._result_label) </ins><span class="cx"> </span><span class="cx"> def setup_context(self, query, context): </span><span class="cx"> column = self._resolve_expr_against_query_aliases(query, self.column, context) </span></span></pre></div> <a id="sqlalchemytrunktestorminheritancequerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/orm/inheritance/query.py (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/orm/inheritance/query.py 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/test/orm/inheritance/query.py 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -538,6 +538,11 @@ </span><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> </span><ins>+ row = sess.query(Engineer.name, Engineer.primary_language).filter(Engineer.name=='dilbert').first() + assert row.name == 'dilbert' + assert row.primary_language == 'java' + + </ins><span class="cx"> self.assertEquals( </span><span class="cx"> sess.query(Engineer.name, Engineer.primary_language).all(), </span><span class="cx"> [(u'dilbert', u'java'), (u'wally', u'c++'), (u'vlad', u'cobol')] </span></span></pre></div> <a id="sqlalchemytrunktestorminheritancesinglepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/orm/inheritance/single.py (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/orm/inheritance/single.py 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/test/orm/inheritance/single.py 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -53,6 +53,10 @@ </span><span class="cx"> session.expire(m1, ['manager_data']) </span><span class="cx"> self.assertEquals(m1.manager_data, "knows how to manage things") </span><span class="cx"> </span><ins>+ row = session.query(Engineer.name, Engineer.employee_id).filter(Engineer.name=='Kurt').first() + assert row.name == 'Kurt' + assert row.employee_id == e1.employee_id + </ins><span class="cx"> @testing.resolve_artifact_names </span><span class="cx"> def test_multi_qualification(self): </span><span class="cx"> session = create_session() </span></span></pre></div> <a id="sqlalchemytrunktestormquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/orm/query.py (5007 => 5008)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/orm/query.py 2008-08-05 09:15:31 UTC (rev 5007) +++ sqlalchemy/trunk/test/orm/query.py 2008-08-05 20:15:28 UTC (rev 5008) </span><span class="lines">@@ -58,6 +58,21 @@ </span><span class="cx"> mapper(User, uni_users) </span><span class="cx"> assert User(id=7) == create_session(bind=testing.db).query(User).get(7) </span><span class="cx"> </span><ins>+class RowTupleTest(QueryTest): + keep_mappers = False + + def setup_mappers(self): + pass + + def test_custom_names(self): + mapper(User, users, properties={ + 'uname':users.c.name + }) + + row = create_session().query(User.id, User.uname).filter(User.id==7).first() + assert row.id == 7 + assert row.uname == 'jack' + </ins><span class="cx"> class GetTest(QueryTest): </span><span class="cx"> def test_get(self): </span><span class="cx"> s = create_session() </span></span></pre> </div> </div> </body> </html> |