Hello all, I am wondering about the most elegant, performant, and robust way to select data from a database and output a delimited file (e.g. CSV). We use MySQL so manually running SELECT ... INTO OUTFILE ... is always possible, and I have colleagues who think that's fine since "we know there will *never* be a tab in the data" ... Personally I hate shelling out to begin with and would always rather use Perl, and I *never* trust that there will *never* be an occurrence of something that can *never* happen. We use DBIx::Class so in application code we are always querying on a DBIC ResultSet.
Naturally I can select data into an AoA with selectall_arrayref() and just use csv() from Text::CSV_XS, but I am wondering if there isn't an interface. I see that perlancar has released DBIx::CSV which provides methods like $dbh->selectall_csv( $sql ), and I have tried it, and it worked. But I have two reservations about it: (1) It extends DBI rather than DBIx::Class, so would require me to "get my hands dirty" selecting the data with DBI, and (2) while the author has created a panoply of interdependent modules, I am always leery of one-person ecosystems, and in this case the backend is another of his/her modules, Text::Table::CSV. I am just solidly in the Text::CSV_XS camp at this point and don't plan to introduce another CSV-handling library.
(Is DBIx::Class extensible, as in, add a keyword something like $rs->search({...})->csv() ?
Thanks for your wisdom.
Edit: clairfy proposed DBI solution
In reply to Select DB data into CSV file by 1nickt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |