[Sqlalchemy-commits] [5889] sqlalchemy/trunk: Lots of fixes to the code examples to specify imports
Brought to you by:
zzzeek
From: <co...@sq...> - 2009-03-31 22:31:13
|
<!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>[5889] sqlalchemy/trunk: Lots of fixes to the code examples to specify imports explicitly.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5889</dd> <dt>Author</dt> <dd>empty</dd> <dt>Date</dt> <dd>2009-03-31 18:31:08 -0400 (Tue, 31 Mar 2009)</dd> </dl> <h3>Log Message</h3> <pre>Lots of fixes to the code examples to specify imports explicitly. Explicit imports make it easier for users to understand the examples. Additionally a lot of the examples were fixed to work with the changes in the 0.5.x code base. One small correction to the Case expression. Thanks a bunch to Adam Lowry! Fixes #717.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkexamplesassociationbasic_associationpy">sqlalchemy/trunk/examples/association/basic_association.py</a></li> <li><a href="#sqlalchemytrunkexamplesassociationproxied_associationpy">sqlalchemy/trunk/examples/association/proxied_association.py</a></li> <li><a href="#sqlalchemytrunkexamplescollectionslarge_collectionpy">sqlalchemy/trunk/examples/collections/large_collection.py</a></li> <li><a href="#sqlalchemytrunkexamplescustom_attributescustom_managementpy">sqlalchemy/trunk/examples/custom_attributes/custom_management.py</a></li> <li><a href="#sqlalchemytrunkexamplescustom_attributeslisten_for_eventspy">sqlalchemy/trunk/examples/custom_attributes/listen_for_events.py</a></li> <li><a href="#sqlalchemytrunkexamplesderived_attributesattributespy">sqlalchemy/trunk/examples/derived_attributes/attributes.py</a></li> <li><a href="#sqlalchemytrunkexamplesdynamic_dictdynamic_dictpy">sqlalchemy/trunk/examples/dynamic_dict/dynamic_dict.py</a></li> <li><a href="#sqlalchemytrunkexampleselementtreeadjacency_listpy">sqlalchemy/trunk/examples/elementtree/adjacency_list.py</a></li> <li><a href="#sqlalchemytrunkexampleselementtreeoptimized_alpy">sqlalchemy/trunk/examples/elementtree/optimized_al.py</a></li> <li><a href="#sqlalchemytrunkexampleselementtreepicklepy">sqlalchemy/trunk/examples/elementtree/pickle.py</a></li> <li><a href="#sqlalchemytrunkexamplesgraphsgraph1py">sqlalchemy/trunk/examples/graphs/graph1.py</a></li> <li><a href="#sqlalchemytrunkexamplesnested_setsnested_setspy">sqlalchemy/trunk/examples/nested_sets/nested_sets.py</a></li> <li><a href="#sqlalchemytrunkexamplespicklecustom_picklerpy">sqlalchemy/trunk/examples/pickle/custom_pickler.py</a></li> <li><a href="#sqlalchemytrunkexamplespoly_assocpoly_assocpy">sqlalchemy/trunk/examples/poly_assoc/poly_assoc.py</a></li> <li><a href="#sqlalchemytrunkexamplespoly_assocpoly_assoc_fkpy">sqlalchemy/trunk/examples/poly_assoc/poly_assoc_fk.py</a></li> <li><a href="#sqlalchemytrunkexamplespoly_assocpoly_assoc_genericpy">sqlalchemy/trunk/examples/poly_assoc/poly_assoc_generic.py</a></li> <li><a href="#sqlalchemytrunkexamplespolymorphconcretepy">sqlalchemy/trunk/examples/polymorph/concrete.py</a></li> <li><a href="#sqlalchemytrunkexamplespolymorphpolymorphpy">sqlalchemy/trunk/examples/polymorph/polymorph.py</a></li> <li><a href="#sqlalchemytrunkexamplespolymorphsinglepy">sqlalchemy/trunk/examples/polymorph/single.py</a></li> <li><a href="#sqlalchemytrunkexamplespostgispostgispy">sqlalchemy/trunk/examples/postgis/postgis.py</a></li> <li><a href="#sqlalchemytrunkexamplesshardingattribute_shardpy">sqlalchemy/trunk/examples/sharding/attribute_shard.py</a></li> <li><a href="#sqlalchemytrunkexamplesverticaldictlikepolymorphicpy">sqlalchemy/trunk/examples/vertical/dictlike-polymorphic.py</a></li> <li><a href="#sqlalchemytrunkexamplesverticaldictlikepy">sqlalchemy/trunk/examples/vertical/dictlike.py</a></li> <li><a href="#sqlalchemytrunkexamplesverticalverticalpy">sqlalchemy/trunk/examples/vertical/vertical.py</a></li> <li><a href="#sqlalchemytrunklibsqlalchemysqlexpressionpy">sqlalchemy/trunk/lib/sqlalchemy/sql/expression.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkexamplesassociationbasic_associationpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/association/basic_association.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/association/basic_association.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/association/basic_association.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -10,13 +10,14 @@ </span><span class="cx"> of the price on each Item (since those can change). </span><span class="cx"> """ </span><span class="cx"> </span><del>-import logging </del><span class="cx"> from datetime import datetime </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, + String, DateTime, Numeric, ForeignKey, and_) +from sqlalchemy.orm import mapper, relation, create_session </ins><span class="cx"> </span><span class="cx"> # Uncomment these to watch database activity. </span><ins>+#import logging </ins><span class="cx"> #logging.basicConfig(format='%(message)s') </span><span class="cx"> #logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) </span><span class="cx"> </span><span class="lines">@@ -72,10 +73,10 @@ </span><span class="cx"> session = create_session() </span><span class="cx"> </span><span class="cx"> # create our catalog </span><del>-session.save(Item('SA T-Shirt', 10.99)) -session.save(Item('SA Mug', 6.50)) -session.save(Item('SA Hat', 8.99)) -session.save(Item('MySQL Crowbar', 16.99)) </del><ins>+session.add(Item('SA T-Shirt', 10.99)) +session.add(Item('SA Mug', 6.50)) +session.add(Item('SA Hat', 8.99)) +session.add(Item('MySQL Crowbar', 16.99)) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><span class="cx"> # function to return items from the DB </span><span class="lines">@@ -89,10 +90,10 @@ </span><span class="cx"> order.order_items.append(OrderItem(item('SA Mug'))) </span><span class="cx"> order.order_items.append(OrderItem(item('MySQL Crowbar'), 10.99)) </span><span class="cx"> order.order_items.append(OrderItem(item('SA Hat'))) </span><del>-session.save(order) </del><ins>+session.add(order) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> # query the order, print items </span><span class="cx"> order = session.query(Order).filter_by(customer_name='john smith').one() </span></span></pre></div> <a id="sqlalchemytrunkexamplesassociationproxied_associationpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/association/proxied_association.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/association/proxied_association.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/association/proxied_association.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -2,8 +2,9 @@ </span><span class="cx"> the usage of the associationproxy extension.""" </span><span class="cx"> </span><span class="cx"> from datetime import datetime </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, + String, DateTime, Float, ForeignKey, and_) +from sqlalchemy.orm import mapper, relation, create_session </ins><span class="cx"> from sqlalchemy.ext.associationproxy import AssociationProxy </span><span class="cx"> </span><span class="cx"> engine = create_engine('sqlite://') </span><span class="lines">@@ -82,7 +83,7 @@ </span><span class="cx"> session.add(order) </span><span class="cx"> session.flush() </span><span class="cx"> </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> # query the order, print items </span><span class="cx"> order = session.query(Order).filter_by(customer_name='john smith').one() </span></span></pre></div> <a id="sqlalchemytrunkexamplescollectionslarge_collectionpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/collections/large_collection.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/collections/large_collection.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/collections/large_collection.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -4,8 +4,10 @@ </span><span class="cx"> presents a more refined version of some of these patterns. </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import (mapper, relation, create_session, MapperExtension, + object_session) + </ins><span class="cx"> meta = MetaData('sqlite://') </span><span class="cx"> meta.bind.echo = True </span><span class="cx"> </span><span class="lines">@@ -56,11 +58,11 @@ </span><span class="cx"> org.members.append(Member('member two')) </span><span class="cx"> org.members.append(Member('member three')) </span><span class="cx"> </span><del>-sess.save(org) </del><ins>+sess.add(org) </ins><span class="cx"> </span><span class="cx"> print "-------------------------\nflush one - save org + 3 members" </span><span class="cx"> sess.flush() </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> # reload. load the org and some child members </span><span class="cx"> print "-------------------------\nload subset of members" </span><span class="lines">@@ -68,7 +70,7 @@ </span><span class="cx"> members = org.member_query.filter(member_table.c.name.like('%member t%')).all() </span><span class="cx"> print members </span><span class="cx"> </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> </span><span class="cx"> # reload. create some more members and flush, without loading any of the original members </span><span class="lines">@@ -80,7 +82,7 @@ </span><span class="cx"> print "-------------------------\nflush two - save 3 more members" </span><span class="cx"> sess.flush() </span><span class="cx"> </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> org = sess.query(Organization).get(org.org_id) </span><span class="cx"> </span><span class="cx"> # now delete. note that this will explictily delete members four, five and six because they are in the session, </span></span></pre></div> <a id="sqlalchemytrunkexamplescustom_attributescustom_managementpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/custom_attributes/custom_management.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/custom_attributes/custom_management.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/custom_attributes/custom_management.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -9,8 +9,10 @@ </span><span class="cx"> with a custom attribute system as well. </span><span class="cx"> </span><span class="cx"> """ </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, Text, + ForeignKey) +from sqlalchemy.orm import (mapper, relation, create_session, + InstrumentationManager) </ins><span class="cx"> </span><span class="cx"> from sqlalchemy.orm.attributes import set_attribute, get_attribute, del_attribute, is_instrumented </span><span class="cx"> from sqlalchemy.orm.collections import collection_adapter </span><span class="lines">@@ -170,10 +172,10 @@ </span><span class="cx"> assert isinstance(a1.bs, MyCollection) </span><span class="cx"> </span><span class="cx"> sess = create_session() </span><del>- sess.save(a1) </del><ins>+ sess.add(a1) </ins><span class="cx"> </span><span class="cx"> sess.flush() </span><del>- sess.clear() </del><ins>+ sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> a1 = sess.query(A).get(a1.id) </span><span class="cx"> </span><span class="lines">@@ -184,7 +186,7 @@ </span><span class="cx"> a1.bs.remove(a1.bs[0]) </span><span class="cx"> </span><span class="cx"> sess.flush() </span><del>- sess.clear() </del><ins>+ sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> a1 = sess.query(A).get(a1.id) </span><span class="cx"> assert len(a1.bs) == 1 </span></span></pre></div> <a id="sqlalchemytrunkexamplescustom_attributeslisten_for_eventspy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/custom_attributes/listen_for_events.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/custom_attributes/listen_for_events.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/custom_attributes/listen_for_events.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -39,8 +39,8 @@ </span><span class="cx"> </span><span class="cx"> if __name__ == '__main__': </span><span class="cx"> </span><del>- from sqlalchemy import * - from sqlalchemy.orm import * </del><ins>+ from sqlalchemy import Column, Integer, String, ForeignKey + from sqlalchemy.orm import relation </ins><span class="cx"> from sqlalchemy.ext.declarative import declarative_base </span><span class="cx"> </span><span class="cx"> class Base(object): </span><span class="lines">@@ -82,4 +82,4 @@ </span><span class="cx"> m1.related.mapped.append(MyMappedClass(data='m2')) </span><span class="cx"> del m1.data </span><span class="cx"> </span><del>- </del><span class="cx">\ No newline at end of file </span><ins>+ </ins></span></pre></div> <a id="sqlalchemytrunkexamplesderived_attributesattributespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/derived_attributes/attributes.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/derived_attributes/attributes.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/derived_attributes/attributes.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -36,8 +36,8 @@ </span><span class="cx"> </span><span class="cx"> ### Example code </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer +from sqlalchemy.orm import mapper, create_session </ins><span class="cx"> </span><span class="cx"> metadata = MetaData('sqlite://') </span><span class="cx"> metadata.bind.echo = True </span><span class="lines">@@ -99,14 +99,14 @@ </span><span class="cx"> intervals = [Interval1(1,4), Interval1(3,15), Interval1(11,16)] </span><span class="cx"> </span><span class="cx"> for interval in intervals: </span><del>- session.save(interval) - session.save(Interval2(interval.start, interval.length)) </del><ins>+ session.add(interval) + session.add(Interval2(interval.start, interval.length)) </ins><span class="cx"> </span><span class="cx"> session.flush() </span><span class="cx"> </span><span class="cx"> print "Clear the cache and do some queries" </span><span class="cx"> </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> for Interval in (Interval1, Interval2): </span><span class="cx"> print "Querying using interval class %s" % Interval.__name__ </span></span></pre></div> <a id="sqlalchemytrunkexamplesdynamic_dictdynamic_dictpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/dynamic_dict/dynamic_dict.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/dynamic_dict/dynamic_dict.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/dynamic_dict/dynamic_dict.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -40,8 +40,8 @@ </span><span class="cx"> self.collection.append(value) </span><span class="cx"> </span><span class="cx"> from sqlalchemy.ext.declarative import declarative_base </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import create_engine, Column, Integer, String, ForeignKey +from sqlalchemy.orm import sessionmaker, dynamic_loader </ins><span class="cx"> </span><span class="cx"> Base = declarative_base(engine=create_engine('sqlite://')) </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexampleselementtreeadjacency_listpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/elementtree/adjacency_list.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/elementtree/adjacency_list.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/elementtree/adjacency_list.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -7,8 +7,9 @@ </span><span class="cx"> """ </span><span class="cx"> </span><span class="cx"> ################################# PART I - Imports/Coniguration ########################################### </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, + Unicode, and_) +from sqlalchemy.orm import mapper, relation, create_session, lazyload </ins><span class="cx"> </span><span class="cx"> import sys, os, StringIO, re </span><span class="cx"> </span><span class="lines">@@ -22,8 +23,7 @@ </span><span class="cx"> #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) </span><span class="cx"> </span><span class="cx"> </span><del>-from elementtree import ElementTree -from elementtree.ElementTree import Element, SubElement </del><ins>+from xml.etree import ElementTree </ins><span class="cx"> </span><span class="cx"> meta = MetaData() </span><span class="cx"> meta.bind = 'sqlite://' </span><span class="lines">@@ -157,14 +157,14 @@ </span><span class="cx"> for file in ('test.xml', 'test2.xml', 'test3.xml'): </span><span class="cx"> filename = os.path.join(os.path.dirname(sys.argv[0]), file) </span><span class="cx"> doc = ElementTree.parse(filename) </span><del>- session.save(Document(file, doc)) </del><ins>+ session.add(Document(file, doc)) </ins><span class="cx"> </span><span class="cx"> print "\nSaving three documents...", line </span><span class="cx"> session.flush() </span><span class="cx"> print "Done." </span><span class="cx"> </span><span class="cx"> # clear session (to illustrate a full load), restore </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> print "\nFull text of document 'text.xml':", line </span><span class="cx"> document = session.query(Document).filter_by(filename="test.xml").first() </span></span></pre></div> <a id="sqlalchemytrunkexampleselementtreeoptimized_alpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/elementtree/optimized_al.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/elementtree/optimized_al.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/elementtree/optimized_al.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -6,8 +6,9 @@ </span><span class="cx"> """ </span><span class="cx"> </span><span class="cx"> ################################# PART I - Imports/Configuration ########################################### </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, + Unicode, and_) +from sqlalchemy.orm import mapper, relation, create_session, lazyload </ins><span class="cx"> </span><span class="cx"> import sys, os, StringIO, re </span><span class="cx"> </span><span class="lines">@@ -21,8 +22,7 @@ </span><span class="cx"> #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) </span><span class="cx"> </span><span class="cx"> </span><del>-from elementtree import ElementTree -from elementtree.ElementTree import Element, SubElement </del><ins>+from xml.etree import ElementTree </ins><span class="cx"> </span><span class="cx"> meta = MetaData() </span><span class="cx"> meta.bind = 'sqlite://' </span><span class="lines">@@ -166,14 +166,14 @@ </span><span class="cx"> for file in ('test.xml', 'test2.xml', 'test3.xml'): </span><span class="cx"> filename = os.path.join(os.path.dirname(sys.argv[0]), file) </span><span class="cx"> doc = ElementTree.parse(filename) </span><del>- session.save(Document(file, doc)) </del><ins>+ session.add(Document(file, doc)) </ins><span class="cx"> </span><span class="cx"> print "\nSaving three documents...", line </span><span class="cx"> session.flush() </span><span class="cx"> print "Done." </span><span class="cx"> </span><span class="cx"> # clear session (to illustrate a full load), restore </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> print "\nFull text of document 'text.xml':", line </span><span class="cx"> document = session.query(Document).filter_by(filename="test.xml").first() </span></span></pre></div> <a id="sqlalchemytrunkexampleselementtreepicklepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/elementtree/pickle.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/elementtree/pickle.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/elementtree/pickle.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -6,8 +6,9 @@ </span><span class="cx"> styles of persistence are identical, as is the structure of the main Document class. </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, String, + PickleType) +from sqlalchemy.orm import mapper, create_session </ins><span class="cx"> </span><span class="cx"> import sys, os </span><span class="cx"> </span><span class="lines">@@ -20,7 +21,7 @@ </span><span class="cx"> # uncomment to show SQL statements and result sets </span><span class="cx"> #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) </span><span class="cx"> </span><del>-from elementtree import ElementTree </del><ins>+from xml.etree import ElementTree </ins><span class="cx"> </span><span class="cx"> engine = create_engine('sqlite://') </span><span class="cx"> meta = MetaData(engine) </span><span class="lines">@@ -53,11 +54,11 @@ </span><span class="cx"> </span><span class="cx"> # save to DB </span><span class="cx"> session = create_session() </span><del>-session.save(Document("test.xml", doc)) </del><ins>+session.add(Document("test.xml", doc)) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><span class="cx"> # clear session (to illustrate a full load), restore </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> document = session.query(Document).filter_by(filename="test.xml").first() </span><span class="cx"> </span><span class="cx"> # print </span></span></pre></div> <a id="sqlalchemytrunkexamplesgraphsgraph1py"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/graphs/graph1.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/graphs/graph1.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/graphs/graph1.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -1,7 +1,7 @@ </span><span class="cx"> """a directed graph example.""" </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, ForeignKey +from sqlalchemy.orm import mapper, relation, create_session </ins><span class="cx"> </span><span class="cx"> import logging </span><span class="cx"> logging.basicConfig() </span><span class="lines">@@ -70,10 +70,10 @@ </span><span class="cx"> n1.add_neighbor(n3) </span><span class="cx"> n2.add_neighbor(n1) </span><span class="cx"> </span><del>-[session.save(x) for x in [n1, n2, n3, n4, n5, n6, n7]] </del><ins>+[session.add(x) for x in [n1, n2, n3, n4, n5, n6, n7]] </ins><span class="cx"> session.flush() </span><span class="cx"> </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> n2 = session.query(Node).get(2) </span><span class="cx"> n3 = session.query(Node).get(3) </span></span></pre></div> <a id="sqlalchemytrunkexamplesnested_setsnested_setspy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/nested_sets/nested_sets.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/nested_sets/nested_sets.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/nested_sets/nested_sets.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -4,9 +4,9 @@ </span><span class="cx"> </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * -from sqlalchemy.orm import attributes </del><ins>+from sqlalchemy import (create_engine, Column, Integer, String, select, case, + func) +from sqlalchemy.orm import sessionmaker, MapperExtension, aliased </ins><span class="cx"> from sqlalchemy.ext.declarative import declarative_base </span><span class="cx"> </span><span class="cx"> engine = create_engine('sqlite://', echo=True) </span></span></pre></div> <a id="sqlalchemytrunkexamplespicklecustom_picklerpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/pickle/custom_pickler.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/pickle/custom_pickler.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/pickle/custom_pickler.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -1,7 +1,8 @@ </span><span class="cx"> """illustrates one way to use a custom pickler that is session-aware.""" </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, PickleType +from sqlalchemy.orm import (mapper, create_session, MapperExtension, + class_mapper, EXT_CONTINUE) </ins><span class="cx"> from sqlalchemy.orm.session import object_session </span><span class="cx"> from cStringIO import StringIO </span><span class="cx"> from pickle import Pickler, Unpickler </span><span class="lines">@@ -28,7 +29,7 @@ </span><span class="cx"> if getattr(obj, "id", None) is None: </span><span class="cx"> sess = MyPickler.sessions.current </span><span class="cx"> newsess = create_session(bind=sess.connection(class_mapper(Bar))) </span><del>- newsess.save(obj) </del><ins>+ newsess.add(obj) </ins><span class="cx"> newsess.flush() </span><span class="cx"> key = "%s:%s" % (type(obj).__name__, obj.id) </span><span class="cx"> return key </span><span class="lines">@@ -74,9 +75,9 @@ </span><span class="cx"> sess = create_session() </span><span class="cx"> f = Foo() </span><span class="cx"> f.bar = Bar('some bar') </span><del>-sess.save(f) </del><ins>+sess.add(f) </ins><span class="cx"> sess.flush() </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> del MyPickler.sessions.current </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplespoly_assocpoly_assocpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/poly_assoc/poly_assoc.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/poly_assoc/poly_assoc.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/poly_assoc/poly_assoc.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -20,8 +20,9 @@ </span><span class="cx"> </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, and_ +from sqlalchemy.orm import (mapper, relation, create_session, class_mapper, + backref) </ins><span class="cx"> </span><span class="cx"> metadata = MetaData('sqlite://') </span><span class="cx"> </span><span class="lines">@@ -124,11 +125,11 @@ </span><span class="cx"> a3.street = '444 park ave.' </span><span class="cx"> </span><span class="cx"> sess = create_session() </span><del>-sess.save(u1) -sess.save(o1) </del><ins>+sess.add(u1) +sess.add(o1) </ins><span class="cx"> sess.flush() </span><span class="cx"> </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> # query objects, get their addresses </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplespoly_assocpoly_assoc_fkpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/poly_assoc/poly_assoc_fk.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/poly_assoc/poly_assoc_fk.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/poly_assoc/poly_assoc_fk.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -19,8 +19,8 @@ </span><span class="cx"> poly_assoc_generic.py. </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import mapper, relation, create_session, class_mapper </ins><span class="cx"> </span><span class="cx"> metadata = MetaData('sqlite://') </span><span class="cx"> </span><span class="lines">@@ -137,11 +137,11 @@ </span><span class="cx"> o1.address.street = '444 park ave.' </span><span class="cx"> </span><span class="cx"> sess = create_session() </span><del>-sess.save(u1) -sess.save(o1) </del><ins>+sess.add(u1) +sess.add(o1) </ins><span class="cx"> sess.flush() </span><span class="cx"> </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> # query objects, get their addresses </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplespoly_assocpoly_assoc_genericpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/poly_assoc/poly_assoc_generic.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/poly_assoc/poly_assoc_generic.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/poly_assoc/poly_assoc_generic.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -6,8 +6,8 @@ </span><span class="cx"> "interface". </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import mapper, relation, create_session, class_mapper </ins><span class="cx"> </span><span class="cx"> metadata = MetaData('sqlite://') </span><span class="cx"> </span><span class="lines">@@ -133,11 +133,11 @@ </span><span class="cx"> o1.address.street = '444 park ave.' </span><span class="cx"> </span><span class="cx"> sess = create_session() </span><del>-sess.save(u1) -sess.save(o1) </del><ins>+sess.add(u1) +sess.add(o1) </ins><span class="cx"> sess.flush() </span><span class="cx"> </span><del>-sess.clear() </del><ins>+sess.expunge_all() </ins><span class="cx"> </span><span class="cx"> # query objects, get their addresses </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplespolymorphconcretepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/polymorph/concrete.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/polymorph/concrete.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/polymorph/concrete.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -1,5 +1,5 @@ </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String +from sqlalchemy.orm import mapper, create_session, polymorphic_union </ins><span class="cx"> </span><span class="cx"> metadata = MetaData() </span><span class="cx"> </span><span class="lines">@@ -56,11 +56,11 @@ </span><span class="cx"> e1 = Engineer("wally", "engineer1") </span><span class="cx"> e2 = Engineer("dilbert", "engineer2") </span><span class="cx"> </span><del>-session.save(m1) -session.save(e1) -session.save(e2) </del><ins>+session.add(m1) +session.add(e1) +session.add(e2) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><del>-employees = session.query(Employee).select() </del><ins>+employees = session.query(Employee) </ins><span class="cx"> print [e for e in employees] </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplespolymorphpolymorphpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/polymorph/polymorph.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/polymorph/polymorph.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/polymorph/polymorph.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -1,5 +1,5 @@ </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import mapper, relation, create_session </ins><span class="cx"> import sets </span><span class="cx"> </span><span class="cx"> # this example illustrates a polymorphic load of two classes </span><span class="lines">@@ -58,12 +58,12 @@ </span><span class="cx"> </span><span class="cx"> person_join = people.outerjoin(engineers).outerjoin(managers) </span><span class="cx"> </span><del>-person_mapper = mapper(Person, people, select_table=person_join,polymorphic_on=people.c.type, polymorphic_identity='person') </del><ins>+person_mapper = mapper(Person, people, polymorphic_on=people.c.type, polymorphic_identity='person') </ins><span class="cx"> mapper(Engineer, engineers, inherits=person_mapper, polymorphic_identity='engineer') </span><span class="cx"> mapper(Manager, managers, inherits=person_mapper, polymorphic_identity='manager') </span><span class="cx"> </span><span class="cx"> mapper(Company, companies, properties={ </span><del>- 'employees': relation(Person, lazy=False, private=True, backref='company') </del><ins>+ 'employees': relation(Person, lazy=False, backref='company', cascade="all, delete-orphan") </ins><span class="cx"> }) </span><span class="cx"> </span><span class="cx"> session = create_session(echo_uow=False) </span><span class="lines">@@ -73,30 +73,30 @@ </span><span class="cx"> c.employees.append(Person(name='joesmith', status='HHH')) </span><span class="cx"> c.employees.append(Engineer(name='wally', status='CGG', engineer_name='engineer2', primary_language='python')) </span><span class="cx"> c.employees.append(Manager(name='jsmith', status='ABA', manager_name='manager2')) </span><del>-session.save(c) </del><ins>+session.add(c) </ins><span class="cx"> </span><span class="cx"> print session.new </span><span class="cx"> session.flush() </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> c = session.query(Company).get(1) </span><span class="cx"> for e in c.employees: </span><del>- print e, e._instance_key, e.company </del><ins>+ print e, e._sa_instance_state.key, e.company </ins><span class="cx"> assert sets.Set([e.name for e in c.employees]) == sets.Set(['pointy haired boss', 'dilbert', 'joesmith', 'wally', 'jsmith']) </span><span class="cx"> print "\n" </span><span class="cx"> </span><del>-dilbert = session.query(Person).get_by(name='dilbert') -dilbert2 = session.query(Engineer).get_by(name='dilbert') </del><ins>+dilbert = session.query(Person).filter_by(name='dilbert').one() +dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() </ins><span class="cx"> assert dilbert is dilbert2 </span><span class="cx"> </span><span class="cx"> dilbert.engineer_name = 'hes dibert!' </span><span class="cx"> </span><span class="cx"> session.flush() </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> c = session.query(Company).get(1) </span><span class="cx"> for e in c.employees: </span><del>- print e, e._instance_key </del><ins>+ print e, e._sa_instance_state.key </ins><span class="cx"> </span><span class="cx"> session.delete(c) </span><span class="cx"> session.flush() </span></span></pre></div> <a id="sqlalchemytrunkexamplespolymorphsinglepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/polymorph/single.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/polymorph/single.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/polymorph/single.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -1,5 +1,5 @@ </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import mapper, relation, create_session </ins><span class="cx"> </span><span class="cx"> metadata = MetaData('sqlite://') </span><span class="cx"> metadata.bind.echo = 'debug' </span><span class="lines">@@ -48,7 +48,7 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> mapper(Company, companies, properties={ </span><del>- 'employees': relation(Person, lazy=True, private=True, backref='company') </del><ins>+ 'employees': relation(Person, lazy=True, backref='company') </ins><span class="cx"> }) </span><span class="cx"> </span><span class="cx"> session = create_session() </span><span class="lines">@@ -58,29 +58,29 @@ </span><span class="cx"> c.employees.append(Person(name='joesmith', status='HHH')) </span><span class="cx"> c.employees.append(Engineer(name='wally', status='CGG', engineer_name='engineer2', primary_language='python')) </span><span class="cx"> c.employees.append(Manager(name='jsmith', status='ABA', manager_name='manager2')) </span><del>-session.save(c) </del><ins>+session.add(c) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> c = session.query(Company).get(1) </span><span class="cx"> for e in c.employees: </span><del>- print e, e._instance_key, e.company </del><ins>+ print e, e._sa_instance_state.key, e.company </ins><span class="cx"> </span><span class="cx"> print "\n" </span><span class="cx"> </span><del>-dilbert = session.query(Person).get_by(name='dilbert') -dilbert2 = session.query(Engineer).get_by(name='dilbert') </del><ins>+dilbert = session.query(Person).filter_by(name='dilbert').one() +dilbert2 = session.query(Engineer).filter_by(name='dilbert').one() </ins><span class="cx"> assert dilbert is dilbert2 </span><span class="cx"> </span><span class="cx"> dilbert.engineer_name = 'hes dibert!' </span><span class="cx"> </span><span class="cx"> session.flush() </span><del>-session.clear() </del><ins>+session.expunge_all() </ins><span class="cx"> </span><span class="cx"> c = session.query(Company).get(1) </span><span class="cx"> for e in c.employees: </span><del>- print e, e._instance_key </del><ins>+ print e, e._sa_instance_state.key </ins><span class="cx"> </span><span class="cx"> session.delete(c) </span><span class="cx"> session.flush() </span></span></pre></div> <a id="sqlalchemytrunkexamplespostgispostgispy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/postgis/postgis.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/postgis/postgis.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/postgis/postgis.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -28,11 +28,10 @@ </span><span class="cx"> * a standalone operator example. </span><span class="cx"> </span><span class="cx"> The implementation is limited to only public, well known </span><del>-and simple to use extension points, with the exception -of one temporary monkeypatch in the DDL extension. -Future SQLAlchemy expansion points may allow more seamless -integration of some features. - </del><ins>+and simple to use extension points. Future SQLAlchemy +expansion points may allow more seamless integration of +some features. + </ins><span class="cx"> """ </span><span class="cx"> </span><span class="cx"> from sqlalchemy.orm.interfaces import AttributeExtension </span><span class="lines">@@ -227,8 +226,9 @@ </span><span class="cx"> </span><span class="cx"> # illustrate usage </span><span class="cx"> if __name__ == '__main__': </span><del>- from sqlalchemy import * - from sqlalchemy.orm import * </del><ins>+ from sqlalchemy import (create_engine, MetaData, Column, Integer, String, + func, literal, select) + from sqlalchemy.orm import sessionmaker, column_property </ins><span class="cx"> from sqlalchemy.ext.declarative import declarative_base </span><span class="cx"> </span><span class="cx"> engine = create_engine('postgres://scott:tiger@localhost/gistest', echo=True) </span></span></pre></div> <a id="sqlalchemytrunkexamplesshardingattribute_shardpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/sharding/attribute_shard.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/sharding/attribute_shard.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/sharding/attribute_shard.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -18,8 +18,9 @@ </span><span class="cx"> """ </span><span class="cx"> </span><span class="cx"> # step 1. imports </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, + String, ForeignKey, Float, DateTime) +from sqlalchemy.orm import sessionmaker, mapper, relation </ins><span class="cx"> from sqlalchemy.orm.shard import ShardedSession </span><span class="cx"> from sqlalchemy.sql import operators </span><span class="cx"> from sqlalchemy import sql </span><span class="lines">@@ -27,10 +28,10 @@ </span><span class="cx"> </span><span class="cx"> # step 2. databases </span><span class="cx"> echo = True </span><del>-db1 = create_engine('sqlite:///shard1.db', echo=echo) -db2 = create_engine('sqlite:///shard2.db', echo=echo) -db3 = create_engine('sqlite:///shard3.db', echo=echo) -db4 = create_engine('sqlite:///shard4.db', echo=echo) </del><ins>+db1 = create_engine('sqlite://', echo=echo) +db2 = create_engine('sqlite://', echo=echo) +db3 = create_engine('sqlite://', echo=echo) +db4 = create_engine('sqlite://', echo=echo) </ins><span class="cx"> </span><span class="cx"> </span><span class="cx"> # step 3. create session function. this binds the shard ids </span><span class="lines">@@ -195,6 +196,6 @@ </span><span class="cx"> north_american_cities = sess.query(WeatherLocation).filter(WeatherLocation.continent == 'North America') </span><span class="cx"> assert [c.city for c in north_american_cities] == ['New York', 'Toronto'] </span><span class="cx"> </span><del>-asia_and_europe = sess.query(WeatherLocation).filter(WeatherLocation.continent.in_('Europe', 'Asia')) </del><ins>+asia_and_europe = sess.query(WeatherLocation).filter(WeatherLocation.continent.in_(['Europe', 'Asia'])) </ins><span class="cx"> assert set([c.city for c in asia_and_europe]) == set(['Tokyo', 'London', 'Dublin']) </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunkexamplesverticaldictlikepolymorphicpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/vertical/dictlike-polymorphic.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/vertical/dictlike-polymorphic.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/vertical/dictlike-polymorphic.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -29,8 +29,8 @@ </span><span class="cx"> future version of SQLAlchemy. </span><span class="cx"> """ </span><span class="cx"> </span><del>-from sqlalchemy.orm.interfaces import PropComparator, MapperProperty -from sqlalchemy.orm import session as sessionlib, comparable_property </del><ins>+from sqlalchemy.orm.interfaces import PropComparator +from sqlalchemy.orm import comparable_property </ins><span class="cx"> </span><span class="cx"> # Using the VerticalPropertyDictMixin from the base example </span><span class="cx"> from dictlike import VerticalPropertyDictMixin </span><span class="lines">@@ -131,7 +131,9 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> if __name__ == '__main__': </span><del>- from sqlalchemy import * </del><ins>+ from sqlalchemy import (MetaData, Table, Column, Integer, Unicode, + ForeignKey, UnicodeText, and_, not_, or_, String, Boolean, cast, text, + null, case) </ins><span class="cx"> from sqlalchemy.orm import mapper, relation, create_session </span><span class="cx"> from sqlalchemy.orm.collections import attribute_mapped_collection </span><span class="cx"> </span><span class="lines">@@ -198,9 +200,9 @@ </span><span class="cx"> stoat[u'cuteness'] = 7 </span><span class="cx"> stoat[u'weasel-like'] = True </span><span class="cx"> </span><del>- session.save(stoat) </del><ins>+ session.add(stoat) </ins><span class="cx"> session.flush() </span><del>- session.clear() </del><ins>+ session.expunge_all() </ins><span class="cx"> </span><span class="cx"> critter = session.query(Animal).filter(Animal.name == u'stoat').one() </span><span class="cx"> print critter[u'color'] </span><span class="lines">@@ -217,14 +219,14 @@ </span><span class="cx"> marten[u'cuteness'] = 5 </span><span class="cx"> marten[u'weasel-like'] = True </span><span class="cx"> marten[u'poisonous'] = False </span><del>- session.save(marten) </del><ins>+ session.add(marten) </ins><span class="cx"> </span><span class="cx"> shrew = Animal(u'shrew') </span><span class="cx"> shrew[u'cuteness'] = 5 </span><span class="cx"> shrew[u'weasel-like'] = False </span><span class="cx"> shrew[u'poisonous'] = True </span><span class="cx"> </span><del>- session.save(shrew) </del><ins>+ session.add(shrew) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><span class="cx"> q = (session.query(Animal). </span></span></pre></div> <a id="sqlalchemytrunkexamplesverticaldictlikepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/vertical/dictlike.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/vertical/dictlike.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/vertical/dictlike.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -122,7 +122,8 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> if __name__ == '__main__': </span><del>- from sqlalchemy import * </del><ins>+ from sqlalchemy import (MetaData, Table, Column, Integer, Unicode, + ForeignKey, UnicodeText, and_, not_) </ins><span class="cx"> from sqlalchemy.orm import mapper, relation, create_session </span><span class="cx"> from sqlalchemy.orm.collections import attribute_mapped_collection </span><span class="cx"> </span><span class="lines">@@ -183,9 +184,9 @@ </span><span class="cx"> # stoat.facts collection: </span><span class="cx"> print stoat.facts[u'color'] </span><span class="cx"> </span><del>- session.save(stoat) </del><ins>+ session.add(stoat) </ins><span class="cx"> session.flush() </span><del>- session.clear() </del><ins>+ session.expunge_all() </ins><span class="cx"> </span><span class="cx"> critter = session.query(Animal).filter(Animal.name == u'stoat').one() </span><span class="cx"> print critter[u'color'] </span><span class="lines">@@ -201,17 +202,17 @@ </span><span class="cx"> marten = Animal(u'marten') </span><span class="cx"> marten[u'color'] = u'brown' </span><span class="cx"> marten[u'cuteness'] = u'somewhat' </span><del>- session.save(marten) </del><ins>+ session.add(marten) </ins><span class="cx"> </span><span class="cx"> shrew = Animal(u'shrew') </span><span class="cx"> shrew[u'cuteness'] = u'somewhat' </span><span class="cx"> shrew[u'poisonous-part'] = u'saliva' </span><del>- session.save(shrew) </del><ins>+ session.add(shrew) </ins><span class="cx"> </span><span class="cx"> loris = Animal(u'slow loris') </span><span class="cx"> loris[u'cuteness'] = u'fairly' </span><span class="cx"> loris[u'poisonous-part'] = u'elbows' </span><del>- session.save(loris) </del><ins>+ session.add(loris) </ins><span class="cx"> session.flush() </span><span class="cx"> </span><span class="cx"> q = (session.query(Animal). </span></span></pre></div> <a id="sqlalchemytrunkexamplesverticalverticalpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/examples/vertical/vertical.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/examples/vertical/vertical.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/examples/vertical/vertical.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -2,8 +2,9 @@ </span><span class="cx"> represented in distinct database rows. This allows objects to be created with dynamically changing </span><span class="cx"> fields that are all persisted in a normalized fashion.""" </span><span class="cx"> </span><del>-from sqlalchemy import * -from sqlalchemy.orm import * </del><ins>+from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, String, + ForeignKey, PickleType, DateTime, and_) +from sqlalchemy.orm import mapper, relation, sessionmaker, scoped_session </ins><span class="cx"> from sqlalchemy.orm.collections import mapped_collection </span><span class="cx"> import datetime </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemysqlexpressionpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/sql/expression.py (5888 => 5889)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/sql/expression.py 2009-03-31 21:59:48 UTC (rev 5888) +++ sqlalchemy/trunk/lib/sqlalchemy/sql/expression.py 2009-03-31 22:31:08 UTC (rev 5889) </span><span class="lines">@@ -2204,13 +2204,17 @@ </span><span class="cx"> whenlist = [(_literal_as_binds(c).self_group(), _literal_as_binds(r)) for (c, r) in whens] </span><span class="cx"> else: </span><span class="cx"> whenlist = [(_no_literals(c).self_group(), _literal_as_binds(r)) for (c, r) in whens] </span><del>- </del><ins>+ </ins><span class="cx"> if whenlist: </span><span class="cx"> type_ = list(whenlist[-1])[-1].type </span><span class="cx"> else: </span><span class="cx"> type_ = None </span><del>- - self.value = value </del><ins>+ + if value is None: + self.value = None + else: + self.value = _literal_as_binds(value) + </ins><span class="cx"> self.type = type_ </span><span class="cx"> self.whens = whenlist </span><span class="cx"> if else_ is not None: </span><span class="lines">@@ -2236,7 +2240,7 @@ </span><span class="cx"> </span><span class="cx"> @property </span><span class="cx"> def _from_objects(self): </span><del>- return itertools.chain(*[x._from_objects for x in self.get_children()]) </del><ins>+ return list(itertools.chain(*[x._from_objects for x in self.get_children()])) </ins><span class="cx"> </span><span class="cx"> class Function(ColumnElement, FromClause): </span><span class="cx"> """Describe a SQL function.""" </span></span></pre> </div> </div> </body> </html> |