DBIx::DBStag 0.08 review

Download
by rbytes.net on

License: Perl Artistic License
File size: 135K
Developer: Chris Mungall
0 stars award from rbytes.net

DBIx::DBStag is a Perl module for Relational Database to Hierarchical (Stag/XML) Mapping.

SYNOPSIS

use DBIx::DBStag;
my $dbh = DBIx::DBStag->connect("dbi:Pg:dbname=moviedb");
my $sql = q[
SELECT
studio.*,
movie.*,
star.*
FROM
studio NATURAL JOIN
movie NATURAL JOIN
movie_to_star NATURAL JOIN
star
WHERE
movie.genre = 'sci-fi' AND star.lastname = 'Fisher'
USE NESTING
(set(studio(movie(star))))
];
my $dataset = $dbh->selectall_stag($sql);
my @studios = $dataset->get_studio;

# returns nested data that looks like this -
#
# (studio
# (name "20th C Fox")
# (movie
# (name "star wars") (genre "sci-fi")
# (star
# (firstname "Carrie")(lastname "Fisher")))))

# iterate through result tree -
foreach my $studio (@studios) {
printf "STUDIO: %sn", $studio->get_name;
my @movies = $studio->get_movie;

foreach my $movie (@movies) {
printf " MOVIE: %s (genre:%s)n",
$movie->get_name, $movie->get_genre;
my @stars = $movie->get_star;

foreach my $star (@stars) {
printf " STARRING: %s:%sn",
$star->get_firstname, $star->get_lastname;
}
}
}

# manipulate data then store it back in the database
my @allstars = $dataset->get("movie/studio/star");
$_->set_fullname($_->get_firstname.' '.$_->get_lastname)
foreach(@allstars);

$dbh->storenode($dataset);
exit 0;

Or from the command line:

unix> selectall_xml.pl -d 'dbi:Pg:dbname=moviebase'
'SELECT * FROM studio NATURAL JOIN movie NATURAL
JOIN movie_to_star NATURAL JOIN star
USE NESTING (set(studio(movie(star))))'

Or using a predefined template:

unix> selectall_xml.pl -d moviebase /mdb-movie genre=sci-fi

Requirements:
Perl

DBIx::DBStag 0.08 keywords