Catalyst::Model::DBIx::Raw - A Catalyst Model for DBIx::Raw
version 0.006
# Use the helper to add a DBIx::Raw model to your application script/myapp_create.pl model Raw DBIx::Raw package YourApp::Model::Raw; use parent 'Catalyst::Model::DBIx::Raw'; __PACKAGE__->config( dsn => 'dsn', user => 'user', password => 'password', ); #or __PACKAGE__->config( conf => '/path/to/conf.pl', ); #or __PACKAGE__->config( dbix_class_model => 'DB', #will use same dbh as DBIx::Class if you have a DBIx::Class model named 'DB' ); 1; package YourApp::Controller::Foo; sub index : Path('/') { my ($self, $c) = @_; my $name = $c->model('Raw')->raw("SELECT name FROM people WHERE id=1"); $c->res->body("Hello, $name!"); } 1;
Catalyst calls this method.
Catalyst::Model::DBIx::Raw takes in all of the same options as config options that DBIx::Raw accepts for new. You can use dsn, user, and password to connect:
dsn
user
password
__PACKAGE__->config( dsn => 'dsn', user => 'user', password => 'password', );
Or you can use a conf file:
__PACKAGE__->config( conf => '/path/to/conf.pl', );
See DBIx::Raw for more information on those options. Additionally, there is one new option in Catalyst::Model::DBIx::Raw, and that is dbix_class_model:
dbix_class_model
__PACKAGE__->config( dbix_class_model => 'DB', );
This is the name of your DBIx::Class model, if you have one. If passed in, Catalyst::Model::DBIx::Raw will reuse the same dbh that DBIx::Class is using. This can be useful if you have DBIx::Class being used for things such as session management or CRUD with forms, but you are using Catalyst::Model::DBIx::Raw to query yourself. This way you do not unecessarily create two database handles. Even if you do not use DBIx::Class in a particular call, Catalyst::Model::DBIx::Raw can still use the DBIx::Class model to get a database handle.
One thing to note is that Catalyst::Model::DBIx::Raw uses the same DBIx::Raw object every request, but gets a new dbh every request using DBIx::Raw's connect method.
Adam Hopkins <srchulo@cpan.org>
This software is copyright (c) 2014 by Adam Hopkins.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::Model::DBIx::Raw, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::DBIx::Raw
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::DBIx::Raw
For more information on module installation, please visit the detailed CPAN module installation guide.