New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-csv-query

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-csv-query

Turn your CSV files to queryable objects

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-csv-query Build Status

Turn your CSV files to queryable objects.

Node-csv-query loads the entire CSV file in memory, thanks to csv-parse, then plug lodash manipulation functions on the loaded dataset. This can be handy for demo project as your code will have a databsae ready syntax while your dataset is easily editable even for non developer.

:warning:Warning:warning:: this library is not meant for performance!

How to use

dataset.csv

id,firstName,lastName,amountOfBooks
1,Olivier,Kaisin,10
2,Emile-Victor,Portenart,2
3,Alex,Mapolice,42
4,Alex,Gaspy,2
Connect to your csv database
'use strict';
    
var csvdb = require("node-csv-query");
var databaseConnection = null;


csvdb(__dirname + "/dataset.csv").then(function (db) {
  databaseConnection = db;
});
How to find the row with firstName=Olivier
databaseConnection.findOne({ 
  firstName: "Olivier" 
}).then(function (record) {
  // Do some stuff
})
How to find the rows with firstName=Alex
databaseConnection.find({ 
  firstName: "Alex" 
}).then(function (record) {
  // Do some stuff
})
How to find the rows with having an 'i' in their firstName

This lib use lodash for querying the dataset. All query format are listed here. node-csv-query will just pass the query param to lodash as the predicate argument.

databaseConnection.find(function (record) {
  return record.firstName.indexOf('i') > -1;
}).then(function (records) {
  // Do some stuff
})
How to deal with different dataset format

This lib is based on csv-parse for parsing csv files. All available options for parsing the CSV are listed here. node-csv-query will just pass these option to csv-parse with the exception of the columns option that will be overrided to true for internal mechanism to works.

dataset_custom.csv

# this dataset has comment & semi colon separator & space before separator
id;firstName   ;lastName ;amountOfBooks
1 ;Olivier     ;Kaisin   ;10
2 ;Emile-Victor;Portenart;2
3 ;Alex        ;Mapolice ;42
4 ;Alex        ;Gaspy    ;2
'use strict';

var csvdb = require("node-csv-query");

csvdb(
  __dirname + "/dataset_custom.csv", { rtrim: true, delimiter: ';', comment: '#' }
).then(function (db) {
  return db.findOne({ 
    firstName: "Olivier" 
  });
}).then(function (record) {
  // Do some stuff
}).catch(function (error) {
  throw error;
});

Compatibility

This lib has been packaged for Node >= v8.9 .

License

MIT

Keywords

FAQs

Package last updated on 10 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc