summaryrefslogtreecommitdiff
path: root/examples/adjacencytree/basic_tree.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-10-16 23:58:35 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-10-16 23:58:35 +0000
commit9e37e8135d4951ca2210fbe71573081247ec83c2 (patch)
tree361763a51bbf40acda47eb2c4bd10846aba671a5 /examples/adjacencytree/basic_tree.py
parenta3cb33357c41cedd2128c9d261208b33a370ad5d (diff)
downloadsqlalchemy-9e37e8135d4951ca2210fbe71573081247ec83c2.tar.gz
Diffstat (limited to 'examples/adjacencytree/basic_tree.py')
-rw-r--r--examples/adjacencytree/basic_tree.py67
1 files changed, 49 insertions, 18 deletions
diff --git a/examples/adjacencytree/basic_tree.py b/examples/adjacencytree/basic_tree.py
index 62a17b8cd..e77ab4f05 100644
--- a/examples/adjacencytree/basic_tree.py
+++ b/examples/adjacencytree/basic_tree.py
@@ -33,6 +33,8 @@ class TreeNode(object):
self.children.append(TreeNode(node))
else:
self.children.append(node)
+ def __repr__(self):
+ return self._getstring(0, False)
def __str__(self):
return self._getstring(0, False)
def _getstring(self, level, expand = False):
@@ -51,19 +53,9 @@ TreeNode.mapper=assignmapper(tables.trees, class_=TreeNode, properties=dict(
name=tables.trees.c.node_name,
parent_id=tables.trees.c.parent_node_id,
root_id=tables.trees.c.root_node_id,
- children=relation(TreeNode, primaryjoin=tables.trees.c.parent_node_id==tables.trees.c.node_id, thiscol=tables.trees.c.node_id, lazy=True, uselist=True, private=True),
+ children=relation(TreeNode, primaryjoin=tables.trees.c.parent_node_id==tables.trees.c.node_id, foreignkey=tables.trees.c.parent_node_id, thiscol=tables.trees.c.node_id, lazy=True, uselist=True, private=True),
))
-
-node = TreeNode('rootnode')
-node.append('node1')
-objectstore.commit()
-
-print node.print_nodes()
-del node.children['node1']
-objectstore.commit()
-sys.exit()
-
node2 = TreeNode('node2')
node2.append('subnode1')
node = TreeNode('rootnode')
@@ -71,31 +63,70 @@ node.append('node1')
node.append(node2)
node.append('node3')
node.children['node2'].append('subnode2')
+
+print "\n\n\n----------------------------"
+print "Created new tree structure:"
+print "----------------------------"
+
print node.print_nodes()
+print "\n\n\n----------------------------"
+print "Committing:"
+print "----------------------------"
+
objectstore.commit()
+print "\n\n\n----------------------------"
+print "Tree After Save:"
+print "----------------------------"
+
+print node.print_nodes()
+
node.append('node4')
node.children['node4'].append('subnode3')
node.children['node4'].append('subnode4')
node.children['node4'].children['subnode3'].append('subsubnode1')
del node.children['node1']
+print "\n\n\n----------------------------"
+print "Modified the tree"
+print "(added node4, node4/subnode3, node4/subnode4,"
+print "node4/subnode3/subsubnode1, deleted node1):"
+print "----------------------------"
+
print node.print_nodes()
+print "\n\n\n----------------------------"
+print "Committing:"
+print "----------------------------"
objectstore.commit()
-id = node.id
+#sys.exit()
-objectstore.clear()
-print "\n\n\n"
+print "\n\n\n----------------------------"
+print "Tree After Save:"
+print "----------------------------"
-t = TreeNode.mapper.select(TreeNode.c.id == id)[0]
+print node.print_nodes()
-print t.print_nodes()
-objectstore.delete(t)
-objectstore.commit()
+nodeid = node.id
+print "\n\n\n----------------------------"
+print "Clearing objectstore, selecting "
+print "tree new where node_id=%d:" % nodeid
+print "----------------------------"
+objectstore.clear()
+t = TreeNode.mapper.select(TreeNode.c.node_id==nodeid)[0]
+print "\n\n\n----------------------------"
+print "Full Tree:"
+print "----------------------------"
+print t.print_nodes()
+print "\n\n\n----------------------------"
+print "Marking root node as deleted"
+print "and committing:"
+print "----------------------------"
+objectstore.delete(t)
+objectstore.commit()