[Catalyst-commits] r14548 - trunk/examples/CatalystAdvent/root/2014

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Mon Dec 15 20:20:13 GMT 2014


Author: jnapiorkowski
Date: 2014-12-15 20:20:13 +0000 (Mon, 15 Dec 2014)
New Revision: 14548

Added:
   trunk/examples/CatalystAdvent/root/2014/16.pod
   trunk/examples/CatalystAdvent/root/2014/17.pod
Log:
16 and 17

Added: trunk/examples/CatalystAdvent/root/2014/16.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2014/16.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2014/16.pod	2014-12-15 20:20:13 UTC (rev 14548)
@@ -0,0 +1,79 @@
+=head1 Instant database admin tool with RapidApp and rdbic.pl
+
+=head1 Overview
+
+The new utility script L<rdbic.pl> from the L<RapidApp> distribution provides 
+instant CRUD access to databases via built-in web server. 
+
+=head1 Introduction
+
+L<RapidApp> is a relatively new extension to L<Catalyst> for quickly creating
+rich and interactive user-interfaces, primarily using ExtJS, with a focus on 
+database-driven applications. L<RapidApp> also provides its own suite of helpers
+to bootstrap new applications which work out-of-the-box.
+
+To showcase some of these capabilities, L<RapidApp> also now ships with the 
+utility script L<rdbic.pl> which wraps the RapidDbic helper trait to generate
+and run a fully-working CRUD application on-the-fly with a single command and
+single L<DBI> connect info (dsn) argument. 
+
+=head1 Installation
+
+To have the L<rdbic.pl> script available on your system, simply install 
+L<RapidApp> from CPAN:
+
+  cpanm RapidApp
+
+=head1 Examples
+
+The temporary application which the L<rdbic.pl> script generates includes a
+full DBIC model loaded with L<DBIx::Class::Schema::Loader>, so all that need
+be supplied is the DBI connect arguments for the database, such as:
+
+  rdbic.pl dbi:mysql:dbname,dbuser,dbpass
+
+The DSN argument is a hybrid connect info with the username and password (if
+required) appended with commas as shown above (note there are no spaces after 
+the commas).
+
+Connections which do not require a user/pass, such as SQLite, can be specified
+simply as:
+
+  rdbic.pl dbi:SQLite:/path/to/sqlt_file.db
+
+As an extra convenience, when connecting to an SQLite database, the argument can
+be supplied as a simple file-system the path to the database file:
+
+  rdbic.pl /path/to/sqlt_file.db
+
+Once the temporary application is generated it is immediately started using the 
+standard L<Catalyst> test server and can be accessed via:
+
+  http://localhost:3500
+
+=head1 Options
+
+The only required argument is the dbi connect string, but other options are also 
+available, such as changing the port and altering the high-level CRUD behavior.
+
+To view the list of options simply call the script with no options or with the
+C<--help> option:
+
+  rdbic.pl --help
+
+
+=head1 Summary
+
+The L<rdbic.pl> script provides an easy introduction to L<RapidApp> and taste
+of the kinds of interfaces which RapidApp facilitates, but is also a useful
+and convenient utility on its own.
+
+In the next article we will look at L<Plack::App::RapidApp::rDbic> which is
+the module used internally by L<rdbic.pl> and can be used and mounted 
+independently within a Plack-based setup. 
+
+=head1 Author
+
+Henry Van Styn L<vanstyn at cpan.org|email:vanstyn at cpan.org>
+
+=cut

Added: trunk/examples/CatalystAdvent/root/2014/17.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2014/17.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2014/17.pod	2014-12-15 20:20:13 UTC (rev 14548)
@@ -0,0 +1,133 @@
+=head1 The Plack::App::RapidApp::rDbic interface to RapidApp
+
+=head1 Overview
+
+In the previous article I introduced the L<RapidApp> utility script L<rdbic.pl> which 
+provides instant CRUD interfaces for L<DBI> databases. In this article we'll look
+at the internal module which L<rdbic.pl> uses, L<Plack::App::RapidApp::rDbic>
+
+=head1 Mounting the rDbic Plack app
+
+Consider the following L<rdbic.pl> command which starts up the CRUD app using 
+a built-in web server:
+
+  rdbic.pl dbi:mysql:mydb,root,''
+
+Internally, this starts a PSGI application using L<Plack::App::RapidApp::rDbic>
+which does the heavy lifting. The above rdbic.pl is roughly equivalent to the following 
+(which could be specified in a .psgi file and started with L<plackup>):
+
+  use Plack::App::RapidApp::rDbic;
+
+  my $app = Plack::App::RapidApp::rDbic->new({
+    connect_info => {
+      dsn      => 'dbi:mysql:mydb',
+      user     => 'root',
+      password => ''
+    }
+  })->to_app;
+
+Under the hood, this generates a fully working RapidApp/Catalyst application into a temp 
+directory, including generation of a L<DBIx::Class::Schema>, L<Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> and L<Plugin::RapidDbic|Catalyst::Plugin::RapidApp::RapidDbic> 
+configuration using the RapidApp bootstrap system.
+
+Alternatively, if you already have a DBIC schema class, you can tell rDbic to use it 
+instead of auto-generating: 
+
+  my $app = Plack::App::RapidApp::rDbic->new({
+    schema_class => 'My::Db::Schema',
+    connect_info => {
+      dsn      => 'dbi:mysql:mydb',
+      user     => 'root',
+      password => ''
+    }
+  })->to_app;
+
+
+You can also supply an already connected schema object:
+
+  my $schema = My::Db::Schema->connect();
+  # ...
+
+  my $app = Plack::App::RapidApp::rDbic->new({
+    schema => $schema
+  })->to_app;
+
+
+This makes it possible to do things like exposing the rDbic a CRUD interface 
+within the structure of an existing Catalyst or PSGI app, such as:
+
+  use MyCatApp;
+  
+  my $app = MyCatApp->apply_default_middlewares(MyCatApp->psgi_app);
+  
+  use Plack::Builder;
+  use Plack::App::RapidApp::rDbic;
+  
+  my $rDbic = Plack::App::RapidApp::rDbic->new({
+    schema => MyCatApp->model('DB')->schema
+  });
+  
+  builder {
+    mount '/'       => $app;
+    mount '/rdbic/' => $rDbic->to_app;
+  };
+
+
+=head1 Configuration
+
+L<rDbic|Plack::App::RapidApp::rDbic> is just a Plack wrapper for a generated RapidApp 
+using L<Plugin::RapidDbic|Catalyst::Plugin::RapidApp::RapidDbic> which provides
+powerful configuration options.
+
+The RapidDbic plugin reads its config from the C<'RapidDbic'> key in DBIC::Schema model,
+and this can be set via the C<model_config> param to rDbic:
+
+  my $app = Plack::App::RapidApp::rDbic->new({
+    schema => $schema,
+    model_config => {
+      RapidDbic => {
+        # join all columns of all first-level relationships in all grids:
+        grid_params => {
+          '*defaults' => {
+            include_colspec => ['*','*.*']
+          }
+        },
+        # Set the display_column for the source named Account to 'fname':
+        TableSpecs => {
+          Account => {
+            display_column => 'fname'
+          },
+        }
+        # ...
+        # ...
+      }
+    }
+  })->to_app;
+
+RapidDbic allows for all kinds of scenarios and customization. For more
+info, see the Chinook demo on the RapidApp website:
+
+=over
+
+=item *
+
+L<http://www.rapidapp.info/demos/chinook>
+
+=back
+
+
+=head1 Summary
+
+L<Plack::App::RapidApp::rDbic> provides a convenient Plack-based interface to a
+runtime loaded L<RapidApp> using L<Plugin::RapidDbic|Catalyst::Plugin::RapidApp::RapidDbic>.
+This is a great place to get started with RapidApp, although it only scratches the surface
+of what can be done.
+
+To learn more or get involved, see the project website at L<www.rapidapp.info|http://www.rapidapp.info> or visit us on IRC in the C<#rapidapp> channel on C<irc.perl.org>. 
+
+=head1 Author
+
+Henry Van Styn L<vanstyn at cpan.org|email:vanstyn at cpan.org>
+
+=cut




More information about the Catalyst-commits mailing list