MPMinus::Store::MultiStore - Multistoring MPMinus::Store::DBI interface
Version 1.05
use MPMinus::Store::MultiStore; # Multistoring my $mso = new MPMinus::Store::MultiStore ( -mso => { foo => { -dsn => 'DBI:mysql:database=TEST;host=192.168.1.1', -user => 'login', -pass => 'password', -attr => { mysql_enable_utf8 => 1, RaiseError => 0, PrintError => 0, }, }, bar => { -dsn => 'DBI:Oracle:SID', -user => 'login', -pass => 'password', -attr => { RaiseError => 0, PrintError => 0, }, }, }, ); my @stores = $mso->stores; # foo, bar $mso->set(baz => new MPMinus::Store::DBI( { -dsn => 'DBI:Oracle:BAZSID', -user => 'login', -pass => 'password', -attr => { RaiseError => 0, PrintError => 0, }, }) ); my @stores = $mso->stores; # foo, bar, baz my $foo = $mso->get('foo'); my $foo = $mso->store('foo'); my $foo = $mso->foo;
Multistoring MPMinus::Store::DBI interface
See MPMinus::Store::DBI
my $mso = new MPMinus::Store::MultiStore ( -mso => { ... }, );
Returns MultiStore object
See also MPMinus::Store::DBI
my $foo = $mso->get('foo'); my $foo = $mso->store('foo'); my $foo = $mso->foo;
Getting specified connection by name
$mso->set(baz => new MPMinus::Store::DBI( { -dsn => 'DBI:Oracle:BAZSID', -user => 'login', -pass => 'password', -attr => { RaiseError => 0, PrintError => 0, }, }) );
Setting specified connection by name and returns state of operation
my @stores = $mso->stores; # foo, bar, baz
Returns current connections as list (array)
package MPM::foo::Handlers; use strict; use MPMinus::Store::MultiStore; use MPMinus::MainTools qw/ msoconf2args /; sub InitHandler { my $pkg = shift; my $m = shift; # MSO Database Nodes if ($m->multistore) { my $mso = $m->multistore; foreach ($mso->stores) { $mso->get($_)->reconnect unless $mso->get($_)->ping; } } else { $m->set( multistore => new MPMinus::Store::MultiStore ( -mso => { msoconf2args($m->conf('store')) }, ) ); } return __PACKAGE__->SUPER::InitHandler($m); } ... package MPM::foo::Test; use strict; sub response { my $m = shift; my $mso = $m->multistore; my $data = $mso->foo->errstr ? $mso->foo->errstr : $mso->foo->field('select sysdate() from dual'); ... return Apache2::Const::OK; }
In conf/mso.conf file:
<store foo> dsn DBI:mysql:database=TEST;host=192.168.1.1 user login pass password <Attr> mysql_enable_utf8 1 RaiseError 0 PrintError 0 </Attr> </store> <store bar> dsn DBI:Oracle:FOOSID user login pass password connect_to 10 request_to 50 <Attr> RaiseError 0 PrintError 0 </Attr> </store> <store baz> dsn DBI:Oracle:BARSID user login pass password <Attr> RaiseError 0 PrintError 0 </Attr> </store>
Init version
Added method for getting list of stores
General refactoring
See CHANGES file
CHANGES
MPMinus::Store::DBI
See TODO file
TODO
* none noted
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE file and https://dev.perl.org/licenses/
LICENSE
To install MPMinus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MPMinus
CPAN shell
perl -MCPAN -e shell install MPMinus
For more information on module installation, please visit the detailed CPAN module installation guide.