Re: [CDBI] Class::DBI::Loader question

[prev] [thread] [next] [Date index for 2004/10/12]

From: Kingsley Kerce
Subject: Re: [CDBI] Class::DBI::Loader question
Date: 18:43 on 12 Oct 2004
Perrin Harkins wrote:
 > Kingsley Kerce wrote:
 > >  Peter Speltz wrote, regarding Class::DBI::Loader:
 > >  > Would it be kind of nice it it dumped "Class::DBI" code (ie
 > >  > the table and column declarations to a file for each table?  I
 > >  > think that may be handy for me but am not sure yet. Anyone
 > >  > written code to make it do that?
 > > 
 > > I've also wanted this, but such a dump would probably best be taken at
 > > least one step farther, to a lower level, such that the dump contains
 > > the results of all your table(), columns(), has_many(), has_a(),
 > > might_have(), etc., calls.
 > 
 > You would be better off doing this with SQL::Translator.  It can 
 > generate Class::DBI code for you as well.

I've just run the latest SQL::Translator's Class::DBI producer against
a PostgreSQL schema of a simple many-to-many relation.  I can't see
how the resulting Class::DBI code would be helpful to anyone.
See appendix, below.

SQL::Translator's Class::DBI producer is dated February 2004, and the
source contains many "fix this"-type comments.  I can't recommend it.

Again, I emphasize that it would be more useful to have a lower-level
dump of Class::DBI's structures -- not Class::DBI code.  Would a
"Class::DBI::Dumper"-type module be a small project for someone with
knowledge of Class::DBI's (and its brethrens') internals?  I'm not that
person, but I could strive to be. :)

Kingsley <kingsley@xxxxxxxxxxxxxxxx.xxx>

# -------------------------------------------------------------------

$ cat schema.sql

CREATE TABLE a_user (
  id SERIAL PRIMARY KEY,
  username VARCHAR(20) NOT NULL,
  password VARCHAR(20) NOT NULL
);

CREATE TABLE role (
  id SERIAL PRIMARY KEY,
  description VARCHAR(30) NOT NULL
);

CREATE TABLE user_role (
  user_id INTEGER NOT NULL REFERENCES a_user(id),
  role_id INTEGER NOT NULL REFERENCES role(id),
  PRIMARY KEY (user_id, role_id)
);

# -------------------------------------------------------------------

$ sqlt -f PostgreSQL -t ClassDBI < schema.sql

package DBI;

# 
# Created by SQL::Translator::Producer::ClassDBI
# Created on Tue Oct 12 14:15:17 2004
# 

use strict;
use base 'Class::DBI::Pg';

DBI->set_db('Main', 'dbi:Pg:_', '', '');

# -------------------------------------------------------------------
package a_user;
use base 'DBI';
use Class::DBI::Pager;

a_user->set_up_table('a_user');


#
# Primary key accessor
#
sub a_user {
    shift->id
}

sub user_roles {
    return shift->user_role_user_id
}

a_user->has_many(
    'user_role_user_id', 'user_role' => 'user_id'
);

sub user_roles { my $self = shift; return map $_->id, $self->user_role_user_id }

# -------------------------------------------------------------------
package role;
use base 'DBI';
use Class::DBI::Pager;

role->set_up_table('role');


#
# Primary key accessor
#
sub role {
    shift->id
}

sub user_roles {
    return shift->user_role_role_id
}

role->has_many(
    'user_role_role_id', 'user_role' => 'role_id'
);

sub user_roles { my $self = shift; return map $_->id, $self->user_role_role_id }

# -------------------------------------------------------------------
package user_role;
use base 'DBI';
use Class::DBI::Pager;

user_role->set_up_table('user_role');


#
# Primary key accessor
#
sub user_role {
    shift->user_id
}

user_role->has_a(
    user_id => 'a_user'
);

sub user_role {
    return shift->user_id
}

user_role->has_a(
    role_id => 'role'
);

sub user_role {
    return shift->role_id
}

1;

# -------------------------------------------------------------------

(message missing)

domain cross talk...?
Michael Jensen 06:47 on 06 Oct 2004

Re: domain cross talk...?
William McKee 14:41 on 06 Oct 2004

Re: domain cross talk...?
Perrin Harkins 14:47 on 06 Oct 2004

Re: domain cross talk...?
William McKee 14:51 on 06 Oct 2004

Re: domain cross talk...?
Perrin Harkins 15:06 on 06 Oct 2004

Re: domain cross talk...?
William McKee 15:32 on 06 Oct 2004

Re: domain cross talk...?
Perrin Harkins 15:36 on 06 Oct 2004

Re: domain cross talk...?
Michael Jensen 16:03 on 06 Oct 2004

Re: domain cross talk...?
Michael Jensen 16:16 on 06 Oct 2004

Re: domain cross talk...?
Perrin Harkins 16:27 on 06 Oct 2004

Re: domain cross talk...?
Carl Johnstone 23:17 on 06 Oct 2004

Re: domain cross talk...?
William McKee 15:53 on 06 Oct 2004

Re: domain cross talk...?
merlyn (Randal L. Schwartz) 16:17 on 06 Oct 2004

Re: domain cross talk...?
Perrin Harkins 16:31 on 06 Oct 2004

[CDBI] Class::DBI::Loader question
Peter Speltz 00:31 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Kingsley Kerce 02:57 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Perrin Harkins 04:12 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Kingsley Kerce 18:43 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Clayton L. Scott 17:08 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Peter Speltz 17:32 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Perrin Harkins 18:58 on 12 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Kingsley Kerce 14:26 on 14 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Perrin Harkins 15:17 on 14 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Tony Bowden 15:39 on 14 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Kingsley Kerce 14:26 on 14 Oct 2004

Re: [CDBI] Class::DBI::Loader question
Tim Bunce 16:22 on 14 Oct 2004

Re: [CDBI] Class::DBI::Loader question
merlyn (Randal L. Schwartz) 17:24 on 14 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52