The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Example::DB - Example class for DBIx::AnyDBD usage

SYNOPSIS

  use Example::DB
  Example::DB->set_dsn('dbi:Pg:dbname=foo');
  Example::DB->set_user('matt');
  Example::DB->set_password('blueberry');
  
  my $db = Example::DB->instance();
  
  my @users = $db->get_users(); # called from Example/DB/Pg.pm
  
  # NB: This is just an example. It is designed not for usage,
  #     but so that you read the source code!

DESCRIPTION

This is a couple of example class files that you can use and adapt in projects that use DBIx::AnyDBD. It is here as an example only, and not meant to be used as-is. That means you should copy the code into your own class hierarchy, rather than use it as Example::*.

The methods of most interest are those in DB/*.pm. These implement the database specific routines for each database. They encapsulate various things about each database, such as the ability to do nested transactions, how to retrieve the current id value for a table, and how dates are encapsulated. For most purposes you should put your SQL inside the Default.pm file, and only put stuff in the database specific files when necessary.