Re: pretty(ish) pictures...

[prev] [thread] [next] [Date index for 2005/07/13]

From: Caroline Johnston
Subject: Re: pretty(ish) pictures...
Date: 15:02 on 13 Jul 2005
Hi again 

Thanks for the feedback.

> On 7/13/05, Ron Savage <ron@xxxxxx.xxx.xx> wrote:
> > On Wed, 13 Jul 2005 08:24:08 +0300, stelf wrote:
> > Have you looked at GraphViz::DBI?

Thanks - I'll have a look. I'm not sure this will work in my case - I've
got an old MySQL DB and it doesn't do foreign keys (at least, I don't
think it does?) so all my relationship info is in my CDBI classes.
 
> Also thanks Caroline, that looks quite useful.. I didn't think that an
> ascii description of schema would be useful and that has changed my
> mind - do you mind If I use some of your C:DBI and ASCII fu in Autodia
> (which currently generates schema from source code, sql and databases
> into XMI, XML, HTML, Dia, Graphviz, Umbrello, etc)

Help yourself ;)  I've been faffing about with it though. You can now call
it as a class method to get the table description and as an object method
to get the contents of that object. I've been using it with
Class::DBI::Loader (example below) and it seems quite handy for debugging,
if nothing else ;)

I'll stick it on CPAN when I figure out how. In the meantime, you can 
svn checkout http://cassj.co.uk/svn/cdwp/trunk/Class-DBI-WithPictures-Ascii

I haven't tried it with anything but MySQL. Let me know if it works with 
others.

Cheers,

Cxx


Class::DBI::Loader example:

############################
package CDBI::Test;

use strict;
use warnings;

use Class::DBI::Loader;

my $loader  = Class::DBI::Loader->new(
                                      dsn       => 'dbi:mysql:test',
                                      user      => 'lpctools',
                                      password  => 'lpctools',
                                      namespace => 'Test::DBI',
                                      additional_classes => 
[qw/Class::DBI::WithPictures::Ascii/],
                                     ) ;
Test::DBI::Widget->has_a(thingy => 'Test::DBI::Thingy');
Test::DBI::Thingy->has_many(widgets => 'Test::DBI::Widget');

sub ascii
{
  foreach ($loader->classes){print $_->ascii->table}
}


###############################
then you can get all your tables, like:

 use CDBI::Test; 
 print CDBI::Test->ascii'
+----------+
| thingy   |
+----------+
| *id      |
| comment  |
| notes    |
+----------+

+---------+
| widget  |
+---------+
| *id     |
| thingy  |-> thingy
+---------+
 
or an individual table like:

 use CDBI::Test;
 print Test::DBI::Widget->ascii->table;

+---------+
| widget  |
+---------+
| *id     |
| thingy  |-> thingy
+---------+

or the values in  an individual object, like:

 use CDBI::Test;
 $obj = Test::DBI::Thingy->retrieve('1');
 print $obj->ascii->table;

+---------------------------+
| thingy                    |
+---------------------------+
| *id      | 1              |
| comment  | this is a test |
| notes    | NULL           |
+---------------------------+

 (you still get the ->wherever for FKs, just this table doesn't have any)
#########################################



pretty(ish) pictures...
Caroline Johnston 16:40 on 12 Jul 2005

Re: pretty(ish) pictures...
stelf 05:24 on 13 Jul 2005

Re: pretty(ish) pictures...
Ron Savage 05:37 on 13 Jul 2005

Re: pretty(ish) pictures...
Aaron Trevena 13:51 on 13 Jul 2005

Re: pretty(ish) pictures...
Caroline Johnston 15:02 on 13 Jul 2005

Re: pretty(ish) pictures...
stelf 17:57 on 13 Jul 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52