Last active
August 29, 2015 14:02
-
-
Save moznion/fd979ff843571b4716ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Your::App::DB::Schema; | |
use strict; | |
use warnings; | |
use Teng::Schema::Declare; | |
table { | |
name "table_name"; | |
pk "id"; | |
columns qw( id col1 col2 col3 ); | |
}; | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Teng; | |
use Your::App::DB::Schema; | |
my $table_name = 'table_name'; | |
my $schema = Your::App::DB::Schema->instance; | |
my $table = $schema->get_table($table_name); | |
open my $fh, '>', "${table_name}_dumped.csv"; | |
my $columns = $table->{columns}; | |
print $fh ';' . join(',', @$columns) . "\n"; | |
my $teng = Teng->new({ | |
# some settings | |
}); | |
my @rows = $teng->search_by_sql(qq{ | |
SELECT * FROM $table_name ORDER BY branch_id ASC | |
}); | |
for my $row (@rows) { | |
my @data; | |
for my $column (@$columns) { | |
(my $data = $row->$column) =~ s/,/\\,/g; | |
push @data, $data; | |
} | |
print $fh join(',', @data) . "\n"; | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment