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

POE::Component::MDBA::Backend::DBIC - DBIx::Class Backend

SYNOPSIS

  use POE qw(Component::MDBA);

  POE::Component::MDBA->spawn(
    alias        => $alias,
    backend      => 'DBIC',
    backend_args => [ { schema => $schema1 }, { schema => $schema2 } ]
  );

  # else where in your code...
  POE::Kernel->post($alias, 'execute', {
    args => [ ... list method arguments ... ]
  });

DESCRIPTION

This module allows you simple access to DBIx::Class via POE::Component::MDBA.

MDBA ARGUMENTS

POE::Component::MDBA::Backend::DBIC influences the arguments passed to POE::Component::MDBA methods:

spawn ARGUMENTS

backend_args

backend_args takes an arrayref of arrayrefs. Each arrayref contains a key value pair. The "schema" key is required, and it should be either a schema class name, or an already connected schema object.

If a class name is passed to the schema argument, you need to specify the connect_info key as well.

  POE::Component::MDBA->spawn(
    backend_args => [
      [
        schema => $schema_object
      ],
      # or 
      [
        schema => $schema_class,
        connect_info => [ 'dbi:Pg:dbname=foo2', 'username2', 'password2', \%attr ]
      ],
      ...
    ]
  );

execute ARGUMENTS

For DBIC, execute() is just a thin dispatcher to each underlying method, which is specified by the rs_method key.

  POE::Kernel->post($alias, 'execute', {
    moniker   => 'Table',
    rs_method => 'search', # default
    ... other arguments to search() ...
  });

  POE::Kernel->post($alias, 'execute', {
    moniker   => 'Table',
    rs_method => 'update',
    ... other arguments to update() ...
  });

Please note that at the time of writing, only search() is supported (because that's the only thing I need for now. patches welcome), and the above "update" example doesn't actually work.

search ARGUMENTS

moniker

The moniker for the resultset you want to operate against.

where

This specifies the WHERE condition given to search()

attrs

The attributes has given to search()

  POE::Kernel->post( $alias, 'execute', {
    args => [
      {
        rs_method => 'search',
        moniker   => 'Foo',
        where     => \%where,
        attrs     => \%attrs,
      }
    ]
  });

aggregate ARGUMENTS

aggregate function takes the usual arguments received from POE::Component::Generic. ARG0 contains $ref, which is a cookie sent by POE::Component::MDBA. ARG1 contains $result, which is the return value from POE::Component::MDBA::Backend::DBI::execute().

The $result value is a hashref containing the following keys:

rows

An arrayref containing the rows resulting from executing the SQL and fetching results from it. The type of each value depends on the value of select_mode passed to execute().

Note that if select_mode is not specified, then the value of this slot is always an empty list.

error

If execute() fails at any point because of an error, then this value is populated with the value of the error. It is likely that if you DBIx::Class failed during execution of a query, you will receive an object in this field.

  {
    rows => [
      $row,
      $row,
      ...
    ],
    error => undef, # undef if no error
  }

METHODS

new

Creates a new POE::Component::MDBA::Backend::DBI instance. Takes a list of arguments, which are directly passed to DBI->connect()

execute

Executes the given query. For DBIC, this just delegates to the appropriate method, denoted by rs_method

search

Runs search() against the moniker you provided.

CAVEATS

You need to use() your schema in your main class (or wherever you're using the returned values), as POE::Component::Generic will execute these in a different memory space.

Because data that's passed from/to POE::Component::Generic goes through serialization, you need to use DBIx::Class::Serialize::Storable if you're using DBIx::Class < 0.08

AUTHOR

Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>

SEE ALSO

POE::Component::MDBA

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html