App-AutoCRUD
view release on metacpan or search on metacpan
examples/Chinook/config_chinook.yaml view on Meta::CPAN
page_size : 50
datasources :
Chinook :
dbh:
connect:
- "dbi:SQLite:dbname=Chinook_Sqlite_AutoIncrementPKs.sqlite"
- ""
- ""
- RaiseError: 1
sqlite_unicode: 1
sqlite_open_flags: 2 # SQLITE_OPEN_READWRITE
tablegroups :
- name: Music
descr: Tables describing music content
node: open
tables :
- Artist
- Album
- Track
examples/Sakila/config_sakila.yaml view on Meta::CPAN
page_size : 50
datasources :
Sakila :
dbh:
connect:
- "dbi:SQLite:dbname=sakila.sqlite"
- ""
- ""
- RaiseError: 1
sqlite_unicode: 1
sqlite_open_flags: 2 # SQLITE_OPEN_READWRITE
# no custom Sakila config yet
lib/App/AutoCRUD.pm view on Meta::CPAN
datasources :
Source1 :
dbh:
connect:
# arguments that will be passed to DBI->connect(...)
# for example :
- dbi:SQLite:dbname=some_file
- "" # user
- "" # password
- RaiseError : 1
sqlite_unicode: 1
Create a file F<crud.psgi> like this :
use App::AutoCRUD;
use YAML qw/LoadFile/;
my $config = LoadFile "/path/to/config.yaml";
my $crud = App::AutoCRUD->new(config => $config);
my $app = $crud->to_app;
Then run the app
lib/App/AutoCRUD.pm view on Meta::CPAN
=head1 CONFIGURATION
The bare minimum for this application to run is to
get some configuration information about how to connect
to datasources. This can be done directly in Perl, like in
the test file F<t/00_autocrud.t> :
my $connect_options = {
RaiseError => 1,
sqlite_unicode => 1,
};
my $config = {
app => {
name => "SomeName"
},
datasources => {
SomeDatabase => {
dbh => {
connect => [$dbi_connect_string, $user, $passwd, $connect_options],
},
lib/App/AutoCRUD.pm view on Meta::CPAN
example under the F<examples/Chinook> directory within this distribution) :
datasources :
Chinook :
dbh:
connect:
- "dbi:SQLite:dbname=Chinook_Sqlite_AutoIncrementPKs.sqlite"
- ""
- ""
- RaiseError: 1
sqlite_unicode: 1
tablegroups :
- name: Music
descr: Tables describing music content
node: open
tables :
- Artist
- Album
- Track
lib/App/AutoCRUD/ConfigDomain.pm view on Meta::CPAN
page_size : 50
datasources :
Chinook :
dbh:
connect:
- "dbi:SQLite:dbname=Chinook_Sqlite_AutoIncrementPKs.sqlite"
- ""
- ""
- RaiseError: 1
sqlite_unicode: 1
sqlite_open_flags: 2 # SQLITE_OPEN_READWRITE
tablegroups :
- name: Music
descr: Tables describing music content
node: open
tables :
- Artist
- Album
- Track
lib/App/AutoCRUD/ConfigDomain.pm view on Meta::CPAN
=head2 datasources
datasources :
Chinook :
dbh:
connect:
- "dbi:SQLite:dbname=/path/to/Chinook_Sqlite_AutoIncrementPKs.sqlite"
- "" # username
- "" # password
- RaiseError: 1 # DBI options
sqlite_unicode: 1
A hashref describing the various databases served by this application.
Each key in the hashref is a short name for accessing the corresponding
datasource; that name will be part of URLs. Each value is a hashref
with the following keys :
=over
=item dbh
t/00_autocrud.t view on Meta::CPAN
use JSON::MaybeXS;
use Encode;
my $sqlite_path = "$FindBin::Bin/data/"
. "Chinook_Sqlite_AutoIncrementPKs_empty_tables.tst_sqlite";
# connect to an in-memory copy of the database
my $in_memory_dbh_copy = sub {
my $connect_options = {
RaiseError => 1,
sqlite_unicode => 1,
};
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:", "", "", $connect_options);
$dbh->sqlite_backup_from_file($sqlite_path);
return $dbh;
};
# setup config
my $config = {
app => { name => "Demo",
t/00_autocrud.t view on Meta::CPAN
},
},
};
# instantiate the app
my $crud = App::AutoCRUD->new(config => $config);
my $app = $crud->to_app;
# we will need a JSON decoder for testing. Since it uses in-memory
# unicode strings, utf8 must be turned off
my $json_obj = JSON::MaybeXS->new->utf8(0);
# start testing
test_psgi $app, sub {
my $cb = shift;
# homepage
my $res = $cb->(GET "/home");
like $res->content, qr/AutoCRUD demo application/, "Title from config";
like $res->content, qr/Chinook/, "Home contains Chinook datasource";
( run in 1.910 second using v1.01-cache-2.11-cpan-88abd93f124 )