#-------------------------------------------------------- # 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |