sql-pipe is a fast, zero-dependency CLI tool that streams CSV data into an in-memory SQLite database for immediate SQL querying. With its efficiency and ease of use, it eliminates the complexities of traditional data processing, allowing users to work seamlessly with CSV and SQL in the terminal.
sql-pipe is a high-performance command-line interface (CLI) tool designed for seamless interaction with CSV data and in-memory SQLite databases. This zero-dependency utility enables users to efficiently pipe CSV input from the standard input (stdin), perform instant SQL queries, and output the results directly as CSV. Built upon the Zig programming language, it allows users to avoid the complexities associated with other tools, such as awk, or the overhead of launching a Python interpreter just for a simple task.
$ curl -s https://example.com/data.csv | sql-pipe 'SELECT region, SUM(revenue) FROM t GROUP BY region ORDER BY 2 DESC'
The tool automatically detects the first row of the CSV file as headers, creating a table called t. Each column's data type is inferred based on the initial rows. If you prefer, a flag can be used to treat all columns as text.
$ printf 'name,age\nAlice,30\nBob,25\nCarol,35' | sql-pipe 'SELECT * FROM t'
$ cat orders.csv | sql-pipe 'SELECT COUNT(*), AVG(amount) FROM t WHERE status = "paid"'
$ cat events.csv \
| sql-pipe 'SELECT user_id, COUNT(*) as n FROM t GROUP BY user_id' \
| sql-pipe 'SELECT * FROM t WHERE n > 100'
| Flag | Description |
|---|---|
-d, --delimiter <char> | Specify a custom input delimiter (default is ,). |
--tsv | Activate tab-separated values format. |
--no-type-inference | Treat all columns as TEXT without auto-detection. |
| Code | Meaning |
|---|---|
0 | Successful execution. |
1 | Usage error (missing query). |
2 | CSV parsing error (detailed with row number). |
3 | SQL execution error (with sqlite3 error message). |
sql-pipe supports only a single table per invocation. For more complex operations involving joins, users can chain multiple sql-pipe calls or utilize Common Table Expressions (CTE).sql-pipe is ideal for users familiar with SQL who work with CSV files in terminal environments, offering a fast and efficient solution for on-the-fly data analysis.
No comments yet.
Sign in to be the first to comment.