Process .csv files with a SQL like syntax.
Work in Progress
Currently supports:
- SELECT
- WHERE
- ORDER BY (single column)
- LIMIT
npm install qsv -g
Or if you're using yarn
yarn global add qsv
For files with headers:
qsv -p "./path/to/my/file.csv" -h
For files without headers:
qsv -p "./path/to/my/file.csv"
After loading the file you will get into REPL mode, indicated by the QSV> prompt. In REPL mode you can use SQL Queries against your .csv file.
SELECT * FROM table
SELECT column1, column2 FROM table
Supported operators
operator | meaning |
---|---|
= | Equal |
<> | Not Equal |
> | Greater Than |
< | Less Than |
>= | Greater Than or Equal |
<= | Less Than or Equal |
Examples
SELECT * FROM table WHERE column1 > 10
SELECT * FROM table WHERE column1 < 10
SELECT * FROM table WHERE column1 >= 10
SELECT * FROM table WHERE column1 <= 10
SELECT * FROM table WHERE column1 <> Peter
SELECT * FROM table WHERE colum2 = Mexico
-- ASC is default for ORDER BY so this
SELECT * FROM table ORDER BY column1
-- is the same as:
SELECT * FROM table ORDER BY column1 ASC
-- For descending order you need to add DESC
SELECT * FROM table ORDER BY column1 DESC
table is just a placeholder, you don't need to specify something that makes sense, just don't leave it blank. column1 and column2 are examples for the header fields.
If your .csv file doesn't have headers omit the -h option. Your table will receive enumerated headers in memory, so you can query it like this:
SELECT 0, 1 FROM table
Options
Option | Verbose Version | Description |
---|---|---|
-h | Indicate that the file to parse has headers | |
-d | Specifiy the delimiter of your file. |