Query on CSV
Query on CSV allows you to perform queries on CSV.
Use Cases
This package is suitable for you if you need to perform some queries on:
- Perform SELECT query
- Perform where query (where, orWhere, whereIn, whereDate e.t.c)
- Perform Sorting
- Perform Limit, Offset
- Perform Aggregate Query (count, sum, avg, max, min)
Installation
npm i csvqry
or
yarn add csvqry
Basic Usage
Just import/require the package before start using it.
As a Node.js Package
const csvq = require("csvqry");
As a ES6 Module
import csvq from "csvqry";
(async () => {
try {
const qb = await csvq.from("example.csv");
let result = qb.get();
console.log(result);
} catch (error) {
console.error("Error initializing csvq:", error);
}
})();
Querying, sorting and get results
You can perform queries on your csv:
let qb = await csvq.from("example.csv");
let result = qb
.select("id", "name")
.where("id", 2)
.orWhere("id", 3)
.whereDate("dob", "2010-10-10")
.whereLike("name", "ruhul")
.whereIn("age", [22, 23, 25, 26])
.whereNotIn("age", [11, 12, 13])
.orderBy("id")
.get();
More Example
let qb = await csvq.from("example.csv");
const result = qb.all();
const result = qb.orderBy("id", "desc").all();
const result = qb.where("id", 1).row();
const result = qb.where("id", 1).first();
const result = qb.where("id", 1).last();
const result = qb.getNth(2);
const result = qb.where("id", 1).hasData();
const result = qb.where("id", 1).exist();
const result = qb.orderBy("id", "desc").all();
Available where operators
=
(default operator, can be omitted)>
<
<=
>=
!=
Available sorting operators
ASC
DESC
(default operator, can be omitted)asc
desc
Limit and Offset
You can add criteria and specify limit and offset for your query results:
let qb = await csvq.from("example.csv");
const result = qb
.select("*")
.orderBy("id")
.limit(10)
.get();
Aggregator Query
You can add criteria and specify limit and offset for your query results:
let qb = await csvq.from("example.csv");
const result = qb.count();
const result = qb.sum("age");
const result = qb.avg("age");
const result = qb.min("age");
const result = qb.max("age");
Support
If you found an issue or had an idea please refer to this section.
Authors