1.1.0 • Published 2 years ago

createcsvfrom v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

CLI CSV Converter

Creates CSV files from various sources via CLI

Installation

npm i -g createcsvfrom

Functions

MongoDB Collection to CSV

Converts a MongoDB collection directly into a CSV file.

Usage

convertCSV mongodb [options]

Options

-u, --uri <uri>                MongoDB uri.
-d, --db <db>                  MongoDB database.
-c, --collection <collection>  MongoDB collection.
-o, --out <out>                OPTIONAL. The CSV result file. Default: result.csv
-q, --query <query>            OPTIONAL. MongoDB query.
-h, --help                     display help for command

Example

convertCSV mongodb -u '<mongodb_uri>' -o output.csv -d my_database -c my_collection -q '{"country": "DE"}'

MongoDB uri example:

mongodb://<my_user>:<my_pw>@<my_host>:<my_port>/<my_default_auth_db>?replicaSet=<my_replica_set>

JSON file to CSV

Converts a JSON file to a CSV file. One JSON object per line.

Usage

convertCSV json [options]

Options

-f, --file <file>  The JSON file to convert to CSV.
-o, --out <out>    OPTIONAL. The CSV result file. Default: result.csv
-h, --help         display help for command

Example

convertCSV json -f '/path/to/json/file.json' -o result.csv

Postgres to CSV

Converts a Postgres table to a CSV file.

Usage

createcsvfrom pg [options]

Options

--uri <uri>      Postgres connection uri.
--host <host>    Postgres host.
--port <port>    Postgres port.
--user <user>    Postgres user.
--pw <password>  Postgres password.
--db <database>  Postgres database.
--query <query>  Postgres query to convert.
-o, --out <out>  OPTIONAL. The CSV result file. Default: result.csv
-h, --help       display help for command

Example

createcsvfrom pg --uri postgresql://<user>:<password>@<host>:<port>/<database> --query 'SELECT * from books limit 5000;' -o ~HOME/output.csv
createcsvfrom pg --host <my_host> --user <my_user> --pw <my_pw> --port <my_port> --db <my_db> --query 'SELECT * from books limit 5000;'