Perl OO persistence with relational database 
Author Message
 Perl OO persistence with relational database

I am developing a web site using the following 'thingies':

RH Linux 7.2
Apache
MySql
Perl DBI
HTML::Template (v. good btw)
Perl
Browser  (Netscape but wish there was an open version of IE!)
Javascript
And a session cookie. (wrote a module based on this very useful
article http://www.*-*-*.com/ )

Works very nicely but I am getting a bit bored with writing Perl
modules for each of my objects/entity_types/tables (anyone fancy
writing a few for me?).  Each one a create, read, delete, update,
list....  The fact that I have a load of procs starting read_xxxx
suggests that I should be using objects to me and in any case I have
figured stuff out up until now and want a new challenge to make sure
that the site is never finished.

I have read the O'Reilly book on Advanced Perl OO and quite fancy
having a go but have the following concern.

The object persistence described in the book basically takes a perl
data structure and flattens it, generates a key and then manipulates
it in some 'generic' entity table.  Difficult for Where clauses, sorts
and the like in my view.  What if I want to keep it all in nice tables
and columns with types and such so that I can do some simple SQL
against it.  I am going to want to run some nice reports. Can anyone
reccommend an approach to doing this?  Suggested reading?

Alternatives I think must be about are:

- code gen all the boring stuff
- use some other 'tool' (used to be called a case tool but is that
showing my age?)
- use some Perl module that does it for me through some nice simple
interface  (fingers crossed)
- read how to do it and write the code using OO
- carry on as is and stop mucking about

And about the reports.  Any nice tool to generate them out there?

Thanks for your help,

O.
------------------



Sat, 08 May 2004 02:45:48 GMT  
 Perl OO persistence with relational database

Owain> [..skip..]

Owain> The object persistence described in the book basically takes a perl
Owain> data structure and flattens it, generates a key and then manipulates
Owain> it in some 'generic' entity table.  Difficult for Where clauses, sorts
Owain> and the like in my view.  What if I want to keep it all in nice tables
Owain> and columns with types and such so that I can do some simple SQL
Owain> against it.  I am going to want to run some nice reports. Can anyone
Owain> reccommend an approach to doing this?  Suggested reading?

Owain> Alternatives I think must be about are:

Owain> - code gen all the boring stuff
Owain> - use some other 'tool' (used to be called a case tool but is that
Owain> showing my age?)
Owain> - use some Perl module that does it for me through some nice simple
Owain> interface  (fingers crossed)
Owain> - read how to do it and write the code using OO
Owain> - carry on as is and stop mucking about

There are exist a number of modules which provide OO interface to
relational databases. Some of them can be used to provide OO
persistence with relational database.

Check this url:

    http://poop.sourceforge.net/

--
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)          TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Sat, 08 May 2004 03:38:55 GMT  
 Perl OO persistence with relational database
Take a look at Tangram: http://www.soundobjectlogic.com/tangram
--
Jean-Louis Leroy
Sound Object Logic
http://www.soundobjectlogic.com


Mon, 10 May 2004 16:58:16 GMT  
 Perl OO persistence with relational database
That is the main question dealing with "languages" and trying to work with
objects.

I've tried several things, but seem that the best solution is work with real
objects
development environment (Smalltalk) and object databases.

Please, is only my opinion.


Quote:
> I am developing a web site using the following 'thingies':

> RH Linux 7.2
> Apache
> MySql
> Perl DBI
> HTML::Template (v. good btw)
> Perl
> Browser  (Netscape but wish there was an open version of IE!)
> Javascript
> And a session cookie. (wrote a module based on this very useful
> article http://www.webtechniques.com/archives/2001/05/perl/ )

> Works very nicely but I am getting a bit bored with writing Perl
> modules for each of my objects/entity_types/tables (anyone fancy
> writing a few for me?).  Each one a create, read, delete, update,
> list....  The fact that I have a load of procs starting read_xxxx
> suggests that I should be using objects to me and in any case I have
> figured stuff out up until now and want a new challenge to make sure
> that the site is never finished.

> I have read the O'Reilly book on Advanced Perl OO and quite fancy
> having a go but have the following concern.

> The object persistence described in the book basically takes a perl
> data structure and flattens it, generates a key and then manipulates
> it in some 'generic' entity table.  Difficult for Where clauses, sorts
> and the like in my view.  What if I want to keep it all in nice tables
> and columns with types and such so that I can do some simple SQL
> against it.  I am going to want to run some nice reports. Can anyone
> reccommend an approach to doing this?  Suggested reading?

> Alternatives I think must be about are:

> - code gen all the boring stuff
> - use some other 'tool' (used to be called a case tool but is that
> showing my age?)
> - use some Perl module that does it for me through some nice simple
> interface  (fingers crossed)
> - read how to do it and write the code using OO
> - carry on as is and stop mucking about

> And about the reports.  Any nice tool to generate them out there?

> Thanks for your help,

> O.
> ------------------




Mon, 17 May 2004 01:10:03 GMT  
 Perl OO persistence with relational database

Quote:
> > Works very nicely but I am getting a bit bored with writing Perl
> > modules for each of my objects/entity_types/tables (anyone fancy
> > writing a few for me?).  Each one a create, read, delete, update,
> > list....  The fact that I have a load of procs starting read_xxxx
> > suggests that I should be using objects to me and in any case I have
> > figured stuff out up until now and want a new challenge to make sure
> > that the site is never finished.
> I've tried several things, but seem that the best solution is work with
real
> objects
> development environment (Smalltalk) and object databases.

> Please, is only my opinion.

there is a way to ease ones life writing OO perl projects: use inheritance.
Your base class may have all generic persistance routines implenented. You
need to overload them only if there is  something special required for this
particular class and you still can call parent's method from overloaded one.
To make base class methods work with individual tables use db tables naming
convention based on class name.

here is the example method from base class:

# --------------------------------------------------------------------------
------
sub load {
    my $self = shift;

    my $class_table = 'C_' . uc($self->{class});
    my $query = "select * from V_ENTITIES inner join $class_table".
    " on V_ENTITIES.ID = $class_table.ID where id = ?";
    my $sth = $self->do_sql($query, $self->{id});
    my $hr = $sth->fetchrow_hashref;
    $hr || return $self->error("No object of class $self->{class} with
id=$self->{id} ".
        'can be found in database', 'db error');

    $self->{lc($_)} = $hr->{$_}
        foreach (keys(%$hr));
    $sth->finish();

Quote:
}



Mon, 17 May 2004 15:33:47 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ANNOUNCE: Tangram 0.08 - Object Persistence in Relational Databases

2. ANNOUNCE: Tangram alpha 2 - Object Persistence in Relational Databases

3. OO Perl Persistence Problem

4. Looking for relational database in perl

5. perl application for bulk loading relational databases

6. RDB, a Relational Database Management System implemented in PERL

7. perl and Relational Databases

8. Perl, NT, and relational databases

9. www and relational databases

10. Relational database for Windows/Windows 95/NT

11. Update, RDB, a Relational Database Manager

12. On FTP archive: RDB (Relational Database Management)

 

 
Powered by phpBB® Forum Software