tomazos has asked for the wisdom of the Perl Monks concerning the following question:
The idea is to try and optimize for ease of use, by trading off performance and reliability. (Update: Reliability in the sense that: the extent to which a developer or user error is caught quickly before it causes more trouble in the system. Is there a better word for this?) Let me put this out there and see what you think.
The relevant points about it as compared to an SQL database: (1) It's typeless. Any scalar, of any length, can be stored in any column. (2) Tables and Columns are automatically created as needed on the fly when they are first used (like perl hash keys). ie No writing CREATE TABLE definitions or ALTER TABLEs. Other than that it is equivilant to DBI::(MySQL|Oracle|*SQL).
Maybe it could be built on top of DBI and MySQL somehow?
use PerlTypelessAutovivifyingDB; my $dbh = PerlTypelessAutovivifyingDB->opendb() or die $!; # open mast +er database file, location set on PerlDB module install my $db = $dbh->db('animals'); # use database 'animals', create it if i +t doesn't exist my $table = $db->table('cats'); # use table 'cats', create it if it do +esn't exist $table->key('name'); # alter table to make column 'name' a unique key, + permanently my @cats = ( { 'name' => 'lucy', 'age' => 2, 'species' => 'lion' }, { 'name' => 'mary', 'age' => 5, 'species' => 'lion' }, { 'name' => 'cindy', 'age' => 10, 'species' => 'tiger' } ) foreach my $cat (@cats) { $table->set(%$cat); # insert or update entry represented by hash i +nto table. # any non-existant columns are autovivified in + the table like in hashes # IF hash assigns a unique key column an exist +ing value # update that entry # ELSE # insert new entry, set any key columns to +a new unique value (eg first available integer) } my $sth = $table->select { $a{'species'} eq 'lion' } ('name', 'age'); +# prepare and execute select name and age where species is lion; foreach (my ($name, $age) = $sth->fetchrow_array()) { print "$name ($age years), "; # print 'lucy (2 years), mary (5 ye +ars)' } $sth->finish(); my $joinedtable = $db->table { $a{'cats.name'} eq $b{'kittens.mothers +name'} } ('cats','kittens'); # join two tables on cats.name == kitten +s.name my $sth2 = $table->select ('cats.name', 'kittens.name'); # default to +leftmost table name in column name conflict foreach (my ($name, $kitten) = $sth2->fetchrow_array()) { print "$name has a kitten $kitten. "; } $sth2->finish(); # database automatically closes itself on block exit
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl Typeless Database
by ikegami (Patriarch) on Jul 02, 2005 at 07:19 UTC | |
by Joost (Canon) on Jul 02, 2005 at 12:00 UTC | |
Re: Perl Typeless Database
by davidrw (Prior) on Jul 02, 2005 at 13:37 UTC | |
Re: Perl Typeless Database
by zentara (Archbishop) on Jul 02, 2005 at 12:52 UTC | |
by davidrw (Prior) on Jul 02, 2005 at 13:41 UTC | |
by adrianh (Chancellor) on Jul 02, 2005 at 15:55 UTC | |
Re: Perl Typeless Database
by CountZero (Bishop) on Jul 02, 2005 at 09:07 UTC | |
by tomazos (Deacon) on Jul 02, 2005 at 12:39 UTC | |
by steves (Curate) on Jul 02, 2005 at 13:38 UTC | |
by tomazos (Deacon) on Jul 02, 2005 at 14:14 UTC | |
by steves (Curate) on Jul 02, 2005 at 14:20 UTC | |
by CountZero (Bishop) on Jul 02, 2005 at 12:51 UTC | |
by tomazos (Deacon) on Jul 02, 2005 at 14:09 UTC | |
Re: Perl Typeless Autovivifying Database
by redhotpenguin (Deacon) on Jul 03, 2005 at 06:15 UTC | |
Re: Perl Typeless Autovivifying Database
by mattr (Curate) on Jul 04, 2005 at 05:17 UTC |