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

Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

In reply to Perl Typeless Autovivifying Database by tomazos

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.