I think a Perl Typeless Autovivifying Database would be cool.
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