You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Gavin Carr <ga...@openfusion.com.au> on 2002/04/17 22:17:31 UTC

RFC: simple OO DBIx::Recordset wrapper

Hi all,

I've got a simple object-oriented wrapper to DBIx::Recordset that I'm
considering releasing to CPAN. I'm interested in getting some feedback
on the interface, specifically, and on whether people think it might be
useful, in general. I'd be happy to hear both from DBIx::Recordset users
and from those who prefer to use DBI directly (for whatever reason).

It's aimed partly at beginners for whom the power and depth of
DBIx::Recordset can be daunting, and partly at experienced
DBIx::Recordset users for use in simple queries with a terser interface
and easy subclassing. Note that the module is focussed on simpler
single-record queries (e.g. reference data); for more complex queries
and sets you're better to use DBIx::Recordset itself.

Name uncertain - perhaps DBIx::RecordObject?

Synopsis:

  use DBIx::RecordObject;

  # Constructor (select), returns a hashref
  $emp1 = DBIx::RecordObject->new(ds => 'test', table => 'emp',
    emp_id => 256);

  # Access the columns as attributes
  print $emp->{emp_id}, $emp->{name}, $emp->{title};

  # Also allows DBIx::Recordset-style parameters and args via hashref
  $emp2 = DBIx::RecordObject->new({
    '!DataSource' => 'test',
    '!Table' => 'emp',
    emp_id => 123,
  });

  # Insert constructor
  $emp3 = DBIx::RecordObject->insert(ds => 'test', table => 'emp',
    serial => 'emp_id', name => 'John Smith', title => 'Janitor');

  # Updates and deletes
  $emp3->update(title => 'Senior Janitor');
  $emp1->update(surname => 'Bloggs');
  $emp2->delete();

Subclassing is supported and encouraged. Typical subclass is 7 lines of
code, so should be accessible even to beginners.

  # e.g. a Test::RecordObject subclass that fixes the data source
  $emp4 = Test::RecordObject->new(table => 'emp', emp_id => 300);

  # e.g. a Test::Employee subclass that also defines the table and the
  #   '!Serial' key
  $emp5 = Test::Employee->new(emp_id => 222);


Hope that gives you enough of an idea. Comments, questions and
suggestions welcome.

Cheers,
Gavin

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org