Commandline utility for easily converting a SQL select statement into csv
Switch branches/tags
Nothing to show
Clone or download
Cannot retrieve the latest commit at this time.
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cli.js
index.js
package.json
readme.md

readme.md

sql2csv

NPM

dat

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

Usage

sql2csv will try to guess the kind of database based on the url if you don't specify the paramter --db <type>

$ sql2csv <datbase url/location> -c <query> --db <postgres,mysql,sqlite>

Example with data to a file

$ sql2csv test.db -c "SELECT * from users"  > users.csv

$ ls
users.csv

$ cat users.csv
ID,name
3,karissa
4,dave
5,ryan

Examples

postgres

$ sql2csv postgres://localhost/debtis -c "SELECT id,amount,debt_type from users"
id,amount,kind
1,80000,student
2,80000,student
3,80000,student
4,80000,
5,80000,student
6,80000,student
7,80234,student
8,300000,auto

sqlite

$ sql2csv test.db -c "SELECT * from users;"
ID,name
3,karissa
4,dave
5,ryan

mysql

TODO

JavaScript

TODO