I'm the author of DBIx::Tree:NestedSet. Out of the box it supports SQLite and MySQL, I'm looking for more database champions to beef up support.
Below is one way you could set up your tree. I did it manually for the sake of verbosity.
Note: I'm about to release a new version of the module (it's currently at 0.12), the most glaring bug it fixes is the broken return value of the various add_* methods.
This module is pretty young, caveat coder. I'm very open to patches and bug fixes, (this module is important to a few apps I've got out there) I won't be abandoning it anytime soon.
#!/usr/bin/perl use DBI; use DBIx::Tree::NestedSet; use Data::Dumper; use strict; my $dbh=DBI->connect('dbi:SQLite:dbname=nested_set') or die($DBI::errs +tr); my $tree=DBIx::Tree::NestedSet->new(dbh=>$dbh,db_type=>'SQLite'); $tree->create_default_table(); $tree->add_child_to_right(term=>'Body Regions'); $tree->add_child_to_right( term=>'Extremities', id=>$tree->get_root() ); my $extremities_id=$tree->get_id_by_key( key_name=>'term', key_value=>'Extremities' ); foreach('Arm','Elbow','Hand'){ $tree->add_child_to_right( term=>$_, id=>$extremities_id ); } my $hand_id=$tree->get_id_by_key( key_name=>'term', key_value=>'Hand' ); $tree->add_child_to_right( id=>$hand_id, term=>'Fingers' ); my $fingers_id=$tree->get_id_by_key( key_name=>'term', key_value=>'Fingers' ); $tree->add_child_to_right( id=>$fingers_id, term=>'Thumbs' ); my $structure=$tree->get_self_and_children_flat(); foreach(@$structure){ print " " x $_->{level}. $_->{term}."\n"; } $dbh->do('drop table nested_set');
-Any sufficiently advanced technology is
indistinguishable from doubletalk.
In reply to Re: Tree Traversal Script/Nested Sets
by Hero Zzyzzx
in thread Tree Traversal Script/Nested Sets
by Raad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |