6 use Getopt::Long::Descriptive;
7 use DBIx::Class::Admin;
9 my ($opts, $usage) = describe_options(
13 ["action" => hidden => { one_of => [
14 ['create|c' => 'Create version diffs needs preversion',],
15 ['upgrade|u' => 'Upgrade the database to the current schema '],
16 ['install|i' => 'Install the schema to the database',],
17 ['deploy|d' => 'Deploy the schema to the database',],
18 ['select|s' => 'Select data from the schema', ],
19 ['insert|i' => 'Insert data into the schema', ],
20 ['update|u' => 'Update data in the schema', ],
21 ['delete|D' => 'Delete data from the schema',],
22 ['op:s' => 'compatiblity option all of the above can be suppied as --op=<action>'],
23 ['help|h' => 'display this help'],
26 ['schema-class|schema|C:s' => 'The class of the schema to load', { required => 1 } ],
27 ['resultset|resultset_class|class|r:s' => 'The resultset to operate on for data manipulation' ],
28 ['config-stanza|S:s' => 'Where in the config to find the connection_info, supply in form MyApp::Model::DB',],
29 ['config|f:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ],
30 ['connect-info|n:s%' => 'Supply the connect info as additonal options ie -I dsn=<dsn> user=<user> password=<pass> '],
31 ['connect:s' => 'Supply the connect info as a json string' ],
32 ['sql-dir|q:s' => 'The directory where sql diffs will be created'],
33 ['sql-type|t:s' => 'The RDBMs flavour you wish to use'],
34 ['version|v:i' => 'Supply a version install'],
35 ['preversion|p:s' => 'The previous version to diff against',],
36 ['set:s' => 'JSON data used to perform data operations' ],
37 ['lib|I:s' => 'Additonal library path to search in'],
38 ['attrs:s' => 'JSON string to be used for the second argument for search'],
39 ['where:s' => 'JSON string to be used for the where clause of search'],
40 ['force' => 'Be forceful with some operations'],
41 ['trace' => 'Turn on DBIx::Class trace output'],
42 ['quiet' => 'Be less verbose'],
52 die "please only use one of --config or --connect-info" if ($opts->{config} and $opts->{connect_info});
54 # option compatability mangle
55 if($opts->{connect}) {
56 $opts->{connect_info} = delete $opts->{connect};
59 my $admin = DBIx::Class::Admin->new( %$opts );
62 my $action = $opts->{action};
64 $action = $opts->{op} if ($action eq 'op');
65 my $res = $admin->$action();
67 print "going to perform action $action\n";
68 if ($action eq 'select') {
71 my $format = $opts->{format} || 'tsv';
72 die('Invalid format') if ($format!~/^tsv|csv$/s);
73 $csv_class = 'Text::CSV_XS';
74 eval{ require Text::CSV_XS };
76 $csv_class = 'Text::CSV_PP';
77 eval{ require Text::CSV_PP };
78 die('The select op requires either the Text::CSV_XS or the Text::CSV_PP module') if ($@);
81 my $csv = $csv_class->new({
82 sep_char => ( $format eq 'tsv' ? "\t" : ',' ),
84 foreach my $row (@$res) {
85 $csv->combine( @$row );
86 print $csv->string()."\n";
94 Aran Deltac <bluefeet@cpan.org>
97 Gordon Irving <goraxe@cpan.org>
101 You may distribute this code under the same terms as Perl itself.