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.

My Biz


In reply to Re: Tree Traversal Script/Nested Sets by Hero Zzyzzx
in thread Tree Traversal Script/Nested Sets by Raad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.