Skip to content

herrfugbaum/qsv

Repository files navigation

Process .csv files with a SQL like syntax.

Build Status codecov Maintainability Mutation Score

Gitter Greenkeeper badge

Work in Progress

Currently supports:

  • SELECT
  • WHERE
  • ORDER BY (single column)
  • LIMIT

qsv demo session

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.

Examples:

SELECT

SELECT * FROM table
SELECT column1, column2 FROM table

WHERE

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

ORDER BY

-- 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.