We want to be able to get data in csv format using a particular sql command. However, it'd be slow to load it into a program and format it into csv just to write it out again. Thankfully, each sql flavored database has its own way to format its results in csv form for fast access, but they're all slightly different. It'd be nice if we didn't have to remember all of those particularities.
Thus, sql2csv takes your SELECT statement and translates it into CSV output on process.stdout for the particular database you want. Its fast, and streaming, because we don't do any transformation -- the data comes directly from the database to be piped to wherever you want.
$ npm install -g sql2csv
$ sql2csv --db <postgres,mysql,sqlite> <datbase url/location> -c <query>
$ sql2csv --db sqlite test.db -c "SELECT * from users" > users.csv$ lsusers.csv$ cat users.csvID,name3,karissa4,dave5,ryan
$ sql2csv --db postgres "postgres://localhost/debtis" -c "SELECT id,amount,debt_type from users"id,amount,kind1,80000,student2,80000,student3,80000,student4,80000,5,80000,student6,80000,student7,80234,student8,300000,auto
$ sql2csv --db sqlite test.db -c "SELECT * from users;"ID,name3,karissa4,dave5,ryan