npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

csvqry

v1.0.5

Published

Make data retrieval query on CSV like laravel `Query Builder`

Downloads

3

Readme

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")
    //.select(['id', 'name'])
    .where("id", 2)
    //.where('id', '>' ,2)
    .orWhere("id", 3)
    //.orWhere('id', '>=', 3)
    .whereDate("dob", "2010-10-10")
    //.whereDate('dob', '>=','2010-10-10')
    .whereLike("name", "ruhul")
    //.whereLike('name', 'ruhul', 'start')
    //.whereLike('name', 'ruhul', 'end')
    .whereIn("age", [22, 23, 25, 26])
    .whereNotIn("age", [11, 12, 13])

    .orderBy("id")
    //.orderBy('id', 'desc')
    //.orderBy('id', 'asc')
    //.latest('id')  // Default Id
    //.oldest('id')  // Default Id
    .get();

More Example

let qb = await csvq.from("example.csv");

// To Get All Result
const result = qb.all();

// To Get All Sorted Result
const result = qb.orderBy("id", "desc").all();

// To Get Specific Row
const result = qb.where("id", 1).row();

// To Get First Result
const result = qb.where("id", 1).first();

// To Get Last Result
const result = qb.where("id", 1).last();

// To Get nth row
const result = qb.getNth(2); // [0-n]

// Check Is row exist
const result = qb.where("id", 1).hasData(); // boolean
const result = qb.where("id", 1).exist(); // boolean

// To Get All Sorted Result
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)
    //.limit(10, 2)
    .get();

Aggregator Query

You can add criteria and specify limit and offset for your query results:

let qb = await csvq.from("example.csv");

// To Get Count
const result = qb.count();

// To Get Sum
const result = qb.sum("age");

// To Get Average
const result = qb.avg("age");

// To Get row with minimum column value
const result = qb.min("age");

// To Get row with maximum column value
const result = qb.max("age");

Support

If you found an issue or had an idea please refer to this section.

Authors