Here's the equivalent code using Class::Tangram:
#-------------------------------------------------------- # define "Person" objects package Person; use base qw(Class::Tangram); $schema = { table => "names", fields => { string => [ qw(first last) ] } }; #-------------------------------------------------------- # define which objects we have in our database package Project; use Tangram::Relational; $dbschema = Tangram::Relational->schema ({ classes => [ 'Person' => $Person::schema ]}); sub schema { $dbschema }; #-------------------------------------------------------- # the main program package main; # connect to the database. my $storage = Tangram::Relational->connect(Project->schema, $dsn, $u, $p); # insert a new Person $storage->insert(Person->new( first => "Harry", last => "Potter" )); # $remote_person refers to a person in the database, # for select queries. my $remote_person = $storage->remote("Person"); if ($storage->select ( $remote_person, $remote_person->{first} eq "Harry" )) { print "Potter is IN THE HOUSE.\n"; } # iterate through all rows for my $person ($storage->select("Person")) { print $person->last.": ".$person->first."\n"; } # delete every row matching "Potter" $storage->erase ($storage->select ( $remote_person, $remote_person->{last} eq "Potter" )); if ($storage->select ( $remote_person, $remote_person->{last} eq "Potter" )) { die "Can't get rid of that damn Harry Potter!"; }

Tangram is very cool. Check out the guided tour. Once you divorce yourself from the concept of tables and rows and start thinking in terms of objects, life becomes a lot easier...


In reply to Re: EZDBI is an easier interface to SQL databases by mugwumpjism
in thread EZDBI is an easier interface to SQL databases by Dominus

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.