PrePAN

Sign in to PrePAN

Database::Accessor Crud for any DB

Good

Synopsis

my $da = Database::Accssor->new({        view     => {name  => 'People'},
        elements => [{ name => 'first_name',
                                 view=>'People' },
                             { name => 'last_name',
                                view => 'People' },
                             { name => 'user_id',
                                view =>'People' } ],
        conditions=>[{left           =>{name =>'First',
                                                      view =>'People'},
                                    right          =>{value=>'Jane'},
                                    operator       =>'=',
                                    open_parenthes =>1,
                                   },
                                   {condition      =>'AND',
                                    left           =>{name=>'Last_name',
                                                      view=>'People'},
                                    right          =>{ value=>'Doe'},
                                    operator       =>'=',
                                    close_parenthes=>1
                                    }
                                    ]
                                    
                     ,
  });
  
  $da->add_condition({left           =>{name =>'country_id',
                                                      view =>'People'},
                                    right          =>{value=>22},
                                    operator       =>'=',
                                    condition      =>'AND',
                                   });
 $da->rertrive($dbh,$container);
 $da->insert($mongo,$container);
 $da->add_condition({left           =>{name =>'country_id',
                                                      view =>'People'},
                                    right          =>{value=>22},
                                    operator       =>'=',
                                    condition      =>'AND',
                                   });
 $da->delete($dbh,$container);
 
 The synopsis above only lists few ways you can use Database::Accessor.

Description

This is the name I finally came up with following alot of test and prototype code and the comments from this http://prepan.org/module/nYgPE9VY5gi

I check about on Cpan the name space is free

Database::Accessor

and is is sort where I want it to be

Comments

This looks useful! I'd like to make a suggestion, though: Instead of creating a {name => "", view => ""} for each element for the "elements" parameter, why not make "elements" take a hashref of {"view" => [name, name, ...]}? It seems this would be more convenient for the user, and your can transform it into the other form internally.

To clarify, the parameter could look something like:

Database::Accssor->new(elements => {People => ["first_name", "last_name", "user_id"]})

This would also eliminate the need for a separate "view" parameter to instantiation, since it would simply be the key-list of "elements".

Please sign up to post a review.