5 dbicdump - Dump a schema using DBIx::Class::Schema::Loader
9 dbicdump <configuration_file>
10 dbicdump [-o <loader_option>=<value> ] <schema_class> <connect_info>
14 $ dbicdump schema.conf
16 $ dbicdump -o dump_directory=./lib \
17 -o components='["InflateColumn::DateTime"]' \
18 MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
20 $ dbicdump -o dump_directory=./lib \
21 -o components='["InflateColumn::DateTime"]' \
23 MyApp::Schema dbi:mysql:database=foo user pass '{ quote_char => "`" }'
25 $ dbicdump -o dump_directory=./lib \
26 -o components='["InflateColumn::DateTime"]' \
27 MyApp::Schema 'dbi:mysql:database=foo;host=domain.tld;port=3306' user pass
29 On Windows that would be:
31 $ dbicdump -o dump_directory=.\lib ^
32 -o components="[q{InflateColumn::DateTime}]" ^
34 MyApp::Schema dbi:mysql:database=foo user pass "{ quote_char => q{`} }"
36 Configuration Files must have schema_class and connect_info sections,
37 an example of a general config file is as follows:
39 schema_class MyApp::Schema
50 components InflateColumn::DateTime
56 Dbicdump generates a L<DBIx::Class> schema using
57 L<DBIx::Class::Schema::Loader/make_schema_at> and dumps it to disk.
59 You can pass any L<DBIx::Class::Schema::Loader::Base> constructor option using
60 C<< -o <option>=<value> >>. For convenience, option names will have C<->
61 replaced with C<_> and values that look like references or quote-like
62 operators will be C<eval>-ed before being passed to the constructor.
64 The C<dump_directory> option defaults to the current directory if not
69 L<DBIx::Class::Schema::Loader>, L<DBIx::Class>.
73 Dagfinn Ilmari Mannsåker C<< <ilmari@ilmari.org> >>
77 Caelum: Rafael Kitover <rkitover@cpan.org>
81 This program is free software; you can redistribute it and/or modify it
82 under the same terms as Perl itself.
93 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
94 require DBIx::Class::Schema::Loader::Base;
98 GetOptions( 'loader-option|o=s%' => \&handle_option );
99 $loader_options->{dump_directory} ||= '.';
102 my $configuration_file = shift @ARGV;
104 Config::Any->load_files( {
106 flatten_to_hash => 1,
107 files => [$configuration_file] } );
109 my $c = (values %$configurations)[0];
111 unless (keys %{$c->{connect_info}} && $c->{schema_class}) {
115 my ($dsn, $user, $pass, $options) =
116 map { $c->{connect_info}->{$_} } qw/dsn user pass options/;
118 $c->{loader_options}->{dump_directory} ||=
119 $loader_options->{dump_directory};
123 $c->{loader_options} || {},
124 [ $dsn, $user, $pass, %{$options} ],
128 my ($schema_class, @loader_connect_info) = @ARGV
131 my $dsn = shift @loader_connect_info;
133 my ($user, $pass) = $dsn =~ /sqlite/i ? ('', '')
134 : splice @loader_connect_info, 0, 2;
136 my @extra_connect_info_opts = map parse_value($_), @loader_connect_info;
141 [ $dsn, $user, $pass, @extra_connect_info_opts ],
150 $value = eval $value if $value =~ /^\s*(?:sub\s*\{|q\w?\s*[^\w\s]|[[{])/;
156 my ($self, $key, $value) = @_;
159 die "Unknown option: $key\n"
160 unless DBIx::Class::Schema::Loader::Base->can($key);
162 $value = parse_value $value;
164 $loader_options->{$key} = $value;