Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Stand-alone Scripts

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


gdiener at excelii

Apr 27, 2012, 6:25 AM

Post #1 of 9 (761 views)
Permalink
Stand-alone Scripts

I'm new to Catalyst and have nearly completed the development of my first Catalyst web site. I'm needing to implement scripts to do some off-line database processing and would like to use the DBIx model created and implemented for the Catalyst site. I'm sure this must be possible, but, I've not been successful.

This is what I have so far:

use strict;
use warnings;
use Data::Dumper;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use DealerDemoSite::Schema::DemoDB;


my $connect_info_args = [.{
dsn => 'dbi:Pg:dbname=dib',
user => '...',
password => '...',
AutoCommit => q{1},
}];

my $schema = DealerDemoSite::Schema::DemoDB->connect($connect_info_args);
print Dumper($schema);

my $demo = $schema->resultset('DemoDB::DddDemo')->find({demoid => 30024});


I'm getting the following error message:

DBIx::Class::Schema::resultset(): Can't find source for DemoDB::DddDemo at ./maint.pl line 28

Within the Catalyst application I able to use the following successfully:

my $demo = $c->model('DemoDB::ddddemo')->find($demoid);


Thanks for your help.
- Glen

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


erik.wasser at iquer

Apr 27, 2012, 6:34 AM

Post #2 of 9 (746 views)
Permalink
Re: Stand-alone Scripts [In reply to]

On 04/27/2012 03:25 PM, Glen Diener wrote:

> my $schema = DealerDemoSite::Schema::DemoDB->connect($connect_info_args);
>
> my $demo = $schema->resultset('DemoDB::DddDemo')->find({demoid => 30024});
>
> I'm getting the following error message:
>
> DBIx::Class::Schema::resultset(): Can't find source for DemoDB::DddDemo at ./maint.pl line 28

Try this:

my $demo = $schema->resultset('DddDemo')->find({demoid => 30024});

--
So long... Erik


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

Apr 27, 2012, 6:35 AM

Post #3 of 9 (742 views)
Permalink
Re: Stand-alone Scripts [In reply to]

On 27 April 2012 14:25, Glen Diener <gdiener [at] excelii> wrote:
> I'm new to Catalyst and have nearly completed the development of my first Catalyst web site. I'm needing to implement scripts to do some off-line database processing and would like to use the DBIx model created and implemented for the Catalyst site. I'm sure this must be possible, but, I've not been successful.

Just a suggestion, but we do it like this:

[. your favourite invocation of FindBin or use of $0 or whatever ]
use Config::JFDI;
my $config = Config::JFDI->open( name => 'MyApp', path => dirname ($Bin) );
...
use MyApp::Schema;
my $schema = MyApp::Schema->connect(
$config->{'Model::DB'}->{connect_info} );
...

It's also possible (likely?) that you just can't connect to the
desired DB due to not having the right juju in pg_hba.conf, do check
that you have the right permissions for the user you're logged in as.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


gdiener at excelii

Apr 27, 2012, 6:54 AM

Post #4 of 9 (743 views)
Permalink
Re: Stand-alone Scripts [In reply to]

Thanks for the suggestion. The error changed to:

DBIx::Class::ResultSet::find(): DBI Connection failed: Can't connect to data source 'ARRAY(0xe8bfa0)' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1176

- Glen


> > my $schema =
> > DealerDemoSite::Schema::DemoDB->connect($connect_info_args);
> >
> > my $demo = $schema->resultset('DemoDB::DddDemo')->find({demoid =>
> > 30024});
> >
> > I'm getting the following error message:
> >
> > DBIx::Class::Schema::resultset(): Can't find source for
> > DemoDB::DddDemo at ./maint.pl line 28
>
> Try this:
>
> my $demo = $schema->resultset('DddDemo')->find({demoid => 30024});
>
> --
> So long... Erik
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

Apr 27, 2012, 7:17 AM

Post #5 of 9 (742 views)
Permalink
Re: Stand-alone Scripts [In reply to]

On 27 April 2012 14:54, Glen Diener <gdiener [at] excelii> wrote:
> Thanks for the suggestion. The error changed to:
>
> DBIx::Class::ResultSet::find(): DBI Connection failed: Can't connect to data source 'ARRAY(0xe8bfa0)' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1176

Then you also need this in your schema base class:

use Catalyst::Model::DBIC::Schema::Types qw/ConnectInfo/;

sub connection {
my $self = shift;
my $info = to_ConnectInfo( scalar (@_) > 1 ? [ @_ ] : $_[0] );
return $self->next::method ($info);
}

or you need to take the [ ... ] out from around your connect info args :)

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

Apr 27, 2012, 7:17 AM

Post #6 of 9 (745 views)
Permalink
Re: Stand-alone Scripts [In reply to]

On 27 April 2012 15:17, Will Crawford <billcrawford1970 [at] gmail> wrote:
> or you need to take the [ ... ] out from around your connect info args :)

Actually, just the latter should help you ... :)

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


gdiener at excelii

Apr 27, 2012, 7:34 AM

Post #7 of 9 (748 views)
Permalink
Re: Stand-alone Scripts [In reply to]

Thanks! Removing the [ .. ] from around the connection information args worked. I now have:

use strict;
use warnings;
use Data::Dumper;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use DealerDemoSite::Schema::DemoDB;

my $connect_info_args = {
dsn => 'dbi:Pg:dbname=dib',
user => '...',
password => '...',
AutoCommit => q{1},
};

my $schema = DealerDemoSite::Schema::DemoDB->connect($connect_info_args);
print Dumper($schema);

my $demo = $schema->resultset('DddDemo')->find(30013);
print Dumper($demo);


My next step is to reference the DB connection parameters from the catalyst configuration as you suggested in a previous post.

Thanks again.
- Glen

----- Original Message -----
> From: "Will Crawford" <billcrawford1970 [at] gmail>
> To: "The elegant MVC web framework" <catalyst [at] lists>
> Sent: Friday, April 27, 2012 9:17:54 AM
> Subject: Re: [Catalyst] Stand-alone Scripts
> On 27 April 2012 15:17, Will Crawford <billcrawford1970 [at] gmail>
> wrote:
> > or you need to take the [ ... ] out from around your connect info
> > args :)
>
> Actually, just the latter should help you ... :)
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


edencardim at gmail

Apr 27, 2012, 8:05 PM

Post #8 of 9 (742 views)
Permalink
Re: Stand-alone Scripts [In reply to]

>>>>> "Glen" == Glen Diener <gdiener [at] excelii> writes:

Glen> Within the Catalyst application I able to use the following
Glen> successfully:

Glen> my $demo = $c->model('DemoDB::ddddemo')->find($demoid);

You should be able to do:

use MyApp;
my $demo = MyApp->model('DemoDB::dddemo')->find($demoid);

If you're concerned about the load time of the other components in your app,
you should be able to add a myapp.pl config containing

{
setup_components => { only => qr/Model::DemoDB/ }
}

This will load only your schema, with the correct configs. (With a bit of
->setup munging you'll be able to eliminate plugins as well)

Or, you can use the "cleaner" route and use a standalone Config::JFDI setup
and decouple everything from the app, which I find to be more troublesome to
maintain.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://edencardim.com http://www.shadowcat.co.uk/servers/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

Apr 30, 2012, 2:11 AM

Post #9 of 9 (728 views)
Permalink
Re: Stand-alone Scripts [In reply to]

Note that you also can load your app to use its config file loading
capabilities and access MyApp->model('DB')->resultset('Foo').

BR Alex


Am 2012-04-27 15:25, schrieb Glen Diener:
> I'm new to Catalyst and have nearly completed the development of my first Catalyst web site. I'm needing to implement scripts to do some off-line database processing and would like to use the DBIx model created and implemented for the Catalyst site. I'm sure this must be possible, but, I've not been successful.
>
> This is what I have so far:
>
> use strict;
> use warnings;
> use Data::Dumper;
> use FindBin qw($Bin);
> use lib "$Bin/../lib";
> use DealerDemoSite::Schema::DemoDB;
>
>
> my $connect_info_args = [.{
> dsn => 'dbi:Pg:dbname=dib',
> user => '...',
> password => '...',
> AutoCommit => q{1},
> }];
>
> my $schema = DealerDemoSite::Schema::DemoDB->connect($connect_info_args);
> print Dumper($schema);
>
> my $demo = $schema->resultset('DemoDB::DddDemo')->find({demoid => 30024});
>
>
> I'm getting the following error message:
>
> DBIx::Class::Schema::resultset(): Can't find source for DemoDB::DddDemo at ./maint.pl line 28
>
> Within the Catalyst application I able to use the following successfully:
>
> my $demo = $c->model('DemoDB::ddddemo')->find($demoid);
>
>
> Thanks for your help.
> - Glen
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.