That patch thing from perlancar is *wild* and I'm glad to learn of it. It might be best for your problem.
DBIx::Class is a little bit of a mismatch because CSV is closer to a View, as I see it, than a data format and to get DBIC to operate at that level, per row CSV writing to strings instead of a stream, it will have a large performance penalty. You could do something like–
my $rs = $schema->resultset("UrTable")->search({ ur => "search" }); my $csv = Text::CSV_XS->new({ binary => 1, auto_diag => 1 }) or die "Cannot use CSV: ", Text::CSV_XS->error_diag; my @headers = $rs->result_source->columns; $csv->say( \*STDOUT, [ @headers ] ); my $cursor = $rs->cursor; while ( my @vals = $cursor->next ) { $csv->say( \*STDOUT, [ @vals ] ); }
It's easy enough to drop in some processing in a as_cvs method in your App::Schema::Result::UrTable package but it would be an expensive way to get it. If I were going to break down and do it, I'd do a custom component class to inherit from; I've done this for JSON. You could do something more meta in App::Schema::ResultSet::UrTable… but I'm not sure what that would look like. I would look at the source of DBIx::Class::ResultClass::HashRefInflator as the basis for ideas.
In reply to Re: Select DB data into CSV file
by Your Mother
in thread Select DB data into CSV file
by 1nickt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |