From 6010afb28f95c7050ca48ddd2e6f65ca6cbae5a1 Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Tue, 31 Mar 2009 22:31:08 +0000 Subject: 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. --- examples/elementtree/adjacency_list.py | 12 ++++++------ examples/elementtree/optimized_al.py | 12 ++++++------ examples/elementtree/pickle.py | 11 ++++++----- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'examples/elementtree') diff --git a/examples/elementtree/adjacency_list.py b/examples/elementtree/adjacency_list.py index 706cc88a0..9efacad87 100644 --- a/examples/elementtree/adjacency_list.py +++ b/examples/elementtree/adjacency_list.py @@ -7,8 +7,9 @@ styles of persistence are identical, as is the structure of the main Document cl """ ################################# PART I - Imports/Coniguration ########################################### -from sqlalchemy import * -from sqlalchemy.orm import * +from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, + Unicode, and_) +from sqlalchemy.orm import mapper, relation, create_session, lazyload import sys, os, StringIO, re @@ -22,8 +23,7 @@ logging.basicConfig() #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) -from elementtree import ElementTree -from elementtree.ElementTree import Element, SubElement +from xml.etree import ElementTree meta = MetaData() meta.bind = 'sqlite://' @@ -157,14 +157,14 @@ session = create_session() for file in ('test.xml', 'test2.xml', 'test3.xml'): filename = os.path.join(os.path.dirname(sys.argv[0]), file) doc = ElementTree.parse(filename) - session.save(Document(file, doc)) + session.add(Document(file, doc)) print "\nSaving three documents...", line session.flush() print "Done." # clear session (to illustrate a full load), restore -session.clear() +session.expunge_all() print "\nFull text of document 'text.xml':", line document = session.query(Document).filter_by(filename="test.xml").first() diff --git a/examples/elementtree/optimized_al.py b/examples/elementtree/optimized_al.py index 8b50f6805..39d35921a 100644 --- a/examples/elementtree/optimized_al.py +++ b/examples/elementtree/optimized_al.py @@ -6,8 +6,9 @@ which joins on only three tables. """ ################################# PART I - Imports/Configuration ########################################### -from sqlalchemy import * -from sqlalchemy.orm import * +from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, + Unicode, and_) +from sqlalchemy.orm import mapper, relation, create_session, lazyload import sys, os, StringIO, re @@ -21,8 +22,7 @@ logging.basicConfig() #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) -from elementtree import ElementTree -from elementtree.ElementTree import Element, SubElement +from xml.etree import ElementTree meta = MetaData() meta.bind = 'sqlite://' @@ -166,14 +166,14 @@ session = create_session() for file in ('test.xml', 'test2.xml', 'test3.xml'): filename = os.path.join(os.path.dirname(sys.argv[0]), file) doc = ElementTree.parse(filename) - session.save(Document(file, doc)) + session.add(Document(file, doc)) print "\nSaving three documents...", line session.flush() print "Done." # clear session (to illustrate a full load), restore -session.clear() +session.expunge_all() print "\nFull text of document 'text.xml':", line document = session.query(Document).filter_by(filename="test.xml").first() diff --git a/examples/elementtree/pickle.py b/examples/elementtree/pickle.py index e7cd86984..53d2ee2b6 100644 --- a/examples/elementtree/pickle.py +++ b/examples/elementtree/pickle.py @@ -6,8 +6,9 @@ structure in distinct rows using two additional mapped entities. Note that the styles of persistence are identical, as is the structure of the main Document class. """ -from sqlalchemy import * -from sqlalchemy.orm import * +from sqlalchemy import (create_engine, MetaData, Table, Column, Integer, String, + PickleType) +from sqlalchemy.orm import mapper, create_session import sys, os @@ -20,7 +21,7 @@ logging.basicConfig() # uncomment to show SQL statements and result sets #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) -from elementtree import ElementTree +from xml.etree import ElementTree engine = create_engine('sqlite://') meta = MetaData(engine) @@ -53,11 +54,11 @@ doc = ElementTree.parse(filename) # save to DB session = create_session() -session.save(Document("test.xml", doc)) +session.add(Document("test.xml", doc)) session.flush() # clear session (to illustrate a full load), restore -session.clear() +session.expunge_all() document = session.query(Document).filter_by(filename="test.xml").first() # print -- cgit v1.2.1