1CGI::Application::PlugiUns:e:rDBCIoCn:t:rSicbhuetmeadC(G3PI)e:r:lApDpolciucmaetnitoant:i:oPnlugin::DBIC::Schema(3)
2
3
4

NAME

6       CGI::Application::Plugin::DBIC::Schema - Easy DBIx::Class access from
7       CGI::Application, inspired by CGI::Application::Plugin::DBH.
8

SYNOPSIS

10           use CGI::Application::Plugin::DBIC::Schema (qw/dbic_config schema resultset rs/);
11
12           sub cgiapp_init{
13
14                   my $c = shift;
15
16                   my $dsn = $c->param('dsn');
17                   my $dbpw = $c->param('dbpw');
18                   my $dbuser = $c->param('dbuser');
19
20                   # Provide a default config.
21
22                   $c->dbic_config({schema=>"My::DB",                  # DBIC class
23                                    connect_info=>[$dsn,$dbuser,$dbpw] # use same args as DBI connect
24                                   });
25
26
27           }
28
29
30           sub setup {
31
32                   my $c = shift;
33
34                   $c->start_mode('runmode1');
35                   $c->run_modes([qw/runmode1 runmode2/]);
36           }
37
38           sub runmode1 {
39
40                   my $c = shift;
41
42                   my $id = $c->param('id);
43                   $c->resultset("My::DB::DemoTable")->find($id);
44
45                   # do something with the object ...
46
47                   return "found it.";
48           }
49
50           sub runmode2 {
51
52                   my $c = shift;
53
54                   $c->schema()->resultset("My::DB::DemoTable")
55                       ->create({name=>"John Doe", address=>"Any Street"});
56
57                   return "created it";
58           }
59

DESCRIPTION

61       CGI::Application::Plugin::DBIC::Schema adds easy access to a
62       DBIx::Class::Schema to your Titanium or CGI::Application modules.  Lazy
63       loading is used to prevent a database connection from being made if the
64       "schema" method is not called during the request.  In other words, the
65       database connection is not created until it is actually needed.
66
67       DBIx::Class has lots of dependencies, and therefore a certain length of
68       compile time, but it works fine in a CGI environment for low volume
69       sites.  If you expect a high volume of traffic, think about FastCGI or
70       other alternatives.
71

METHODS

73   schema($name?)
74       This method will return the default DBIx::Class::Schema instance if no
75       name  is provided.  Provide a schema name to retrieve an alternate
76       schema.  The schema instance is created on the first call to this
77       method, and any subsequent calls will return the same instance.
78
79         my $schema = $c->schema();                 # gets default (unnamed) schema
80
81         # Or ...
82
83         my $schem = $c->schema('my_schema_name');  # gets one of named schemas
84
85   dbic_config($name?, \%connect_info)
86       Used to provide your DBIx::Class::Schema class name, an optional config
87       name, and DBI connection parameters.  For \%config_info supply the same
88       parameter list that you would for DBI::connect.  You may also supply
89       DBIx::Class specifig attributes.  For that see
90       DBIx::Class::Storage::DBI for details.
91
92       The recommended place to call "dbic_config" is in the "cgiapp_init"
93       stage of CGI::Application.  If this method is called after the dbic()
94       method has already been accessed, then it will die with an error
95       message.
96
97               # Setup  default schema config
98
99               $c->dbic_config({schema=>"My::DB",                  # DBIC class
100                                connect_info=>[$dsn,$dbuser,$dbpw] # use same args as DBI connect
101                               });
102
103               # Or, provide additional configs by name.
104
105               $c->dbic_config("another_config",
106                               {schema=>"My::Other::DB",
107                                connect_info=>[$dsn,$dbuser,$dbpw]
108                               });
109
110   resultset($config_name?,$resultset_classname)
111       An alias to $c->schema(...)->resultset(...).
112
113       This method provides DBIx::Class::Resultset access.
114
115          # Use the default dbic schema via 'resultset'.
116
117          $c->resultset("DBICT::Result::Test")->find($id);
118
119
120          # Or use a named config to access resultset via an alternative schema.
121
122          $c->resultset('another_config', "DBICT::Result::Test")->find($id);
123
124          # Or use alias short form, 'rs' with default config
125
126          $c->rs("DBICT::Result::Test")->find($id);
127
128          # Or use alias short form with alternate config/schema
129
130          $c->rs('yet_another_schema', "DBICT::Result::Test")->find($id);
131
132   rs
133       An alias to resultset
134

SEE ALSO

136       DBIx::Class, Titanium, CGI::Application,CGI::Application::Plugin::DBH
137

AUTHOR

139       Gordon Van Amburg <gordon@minipeg.net>
140

LICENSE

142       Copyright (C) 2009 Gordon Van Amburg <gordon@minipeg.net>
143
144       This library is free software. You can modify and or distribute it
145       under the same terms as Perl itself.
146
147
148
149perl v5.34.0                      2021C-G0I7:-:2A2pplication::Plugin::DBIC::Schema(3)
Impressum