GetOptions(
'schema=s' => \my $schema_class,
'class=s' => \my $resultset_class,
+ 'connect=s' => \my $connect,
'op=s' => \my $op,
'set=s' => \my $set,
'where=s' => \my $where,
'trace' => \my $trace,
'quiet' => \my $quiet,
'help' => \my $help,
+ 'tlibs' => \my $t_libs,
);
+if ($t_libs) {
+ unshift( @INC, 't/lib', 'lib' );
+}
+
pod2usage(1) if ($help);
$ENV{DBIX_CLASS_STORAGE_DBI_DEBUG} = 1 if ($trace);
die('No schema specified') if(!$schema_class);
eval("require $schema_class");
die('Unable to load schema') if ($@);
-my $schema = $schema_class->connect();
+$connect = jsonToObj( $connect ) if ($connect);
+my $schema = $schema_class->connect(
+ ( $connect ? @$connect : () )
+);
die('No class specified') if(!$resultset_class);
my $resultset = eval{ $schema->resultset($resultset_class) };
The name of the class, within your schema, that you want to run
the operation on.
+=head2 connect
+
+A JSON array to be passed to your schema class upon connecting.
+The array will need to be compatible with whatever the DBIC
+->connect() method requires.
+
=head2 set
This option must be valid JSON data string and is passed in to
Turns on tracing on the DBI storage, thus printing SQL as it is
executed.
+=head2 tlibs
+
+This option is purely for testing during the DBIC installation. Do
+not use it.
+
=head1 JSON
JSON is a lightweight data-interchange format. It allows you
--- /dev/null
+# vim: filetype=perl
+
+sub run_tests {
+
+ eval{'require JSON'};
+ plan skip_all, 'Install JSON to run this test' if ($@);
+
+ eval{'require Text::CSV_XS'};
+ if ($@) {
+ eval{'require Text::CSV_PP'};
+ plan skip_all, 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
+ }
+
+ plan tests => 5;
+ my $schema = shift;
+
+ my $employees = $schema->resultset('Employee');
+ my $cmd = qq|scripts/dbicadmin --schema=DBICTest::Schema --class=Employee --tlibs --connect='["dbi:SQLite:dbname=t/var/DBIxClass.db","",""]' --force --tlibs|;
+
+ `$cmd --op=insert --set='{name:"Matt"}'`;
+ ok( ($employees->count()==1), 'insert count' );
+
+ my $employee = $employees->find(1);
+ ok( ($employee->name() eq 'Matt'), 'insert valid' );
+
+ `$cmd --op=update --set='{name:"Trout"}'`;
+ $employee = $employees->find(1);
+ ok( ($employee->name() eq 'Trout'), 'update' );
+
+ `$cmd --op=insert --set='{name:"Aran"}'`;
+ my $data = `$cmd --op=select --attrs='{order_by:"name"}'`;
+ ok( ($data=~/Aran.*Trout/s), 'select with attrs' );
+
+ `$cmd --op=delete --where='{name:"Trout"}'`;
+ ok( ($employees->count()==1), 'delete' );
+}
+
+1;