[Dbix-class] RFC: Syntactic sugar

Mark Hedges hedges at ucsd.edu
Thu Mar 30 19:49:56 CEST 2006



On Thu, 30 Mar 2006, Matt S Trout wrote:
> 
> Carl Franks wrote:
> >> package Foo::Schema;
> >> use base qw/DBIx::Class::Schema/;
> >>
> >> __PACKAGE__->declare( ... );
> >>
> >> 1;
> >>
> >> Where ... could be a data structure, a string, a filehandle, a
> >> filename, or undef to read from __DATA__
> > 
> > I like the sound of that, but how about having it point to a
> > "create_tables.sql" file?
> > /very/ DRY :)
> 
> Because DBIx-Class can already generate your deployment SQL for you. There's 
> metadata required at the ORM layer that isn't required at the database layer, 
> so the SQL DDL statements are never going to be sufficient - and cease to be 
> DRY very rapidly as you try to go cross-database anyway.

How about a YAML spec for defining the database schema (and 
optionally DBIC declarative statements) in one easy-to-r/w file:

'My::Foo':
  table: foo
  comments: 'A foo object'
  pk:     
    - bar
    - biz
  belongs_to:
    baz: 'My::Baz'
  has_many:
    bozzes: 'My::Boz'
  fields:
    bar:
      type:  varchar
      limit: 10
    biz:
      type:   int
      signed: no

'My::Baz':
  table: baz
  pk: baz_id
  has_many:
    foos: 'My::Foo'
  fields:
    baz_id:
      type:   int
      signed: no
      keygen: auto_increment
    baz_nut:
      type:   text
    baz_fruit:
      type:   text
  indexes:
    fruit_and_nut:
      - baz_nut
      - baz_fruit
    just_nut:
      - baz_nut
    
'My::Boz':
  table: boz
  pk: boz_id
  belongs_to:
    foo: 'My::Foo'
  fields:
    boz_id:
      type:   int
      signed: no
      keygen: auto_increment

And so forth.

Mark



More information about the Dbix-class mailing list