New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

csv-database

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-database

lightweight CSV database

latest
Source
npmnpm
Version
0.9.2
Version published
Weekly downloads
57
26.67%
Maintainers
1
Weekly downloads
 
Created
Source

csv-database : node.js CSV database

Lightweight CRUD database, using CSV as storage. Powered by Typescript + async/await.

Features :

  • complete CRUD API with model validation
  • native JS object requests
  • Typescript typings
  • concurrency-ready

Usage

> const db = await csvdb("users.csv", ["id","name","mail"]);

> await db.get({mail: "johndoe@github.com"});
[ {id: 1, name: "johndoe", mail: "john@github.com"} ]

> await db.add([{id: 2, name: "stevejobs", mail: "jobs@github.com"}]);

Installation

$ npm install csv-database

API Reference

  • csvdb

csvdb(filename, model [, delimiter]) ⇒ Promise<CsvDatabase>

Returns a database, given a CSV file and its model.

  • ; as default delimiter
  • file is created if it doesn't exist
ParamTypeDescription
filenamestringcsv file
modelstring[]database model
[optional] delimiterstringcustom delimiter

Example

const db = await csvdb("users.csv", ["id","name","mail"], ",");

db.get([predicate]) ⇒ Promise<Object[]>

Returns database content. If given a predicate, returns data that matches its key-values pairs.

  • empty array if nothing found
  • throws an error if predicate does not match csv model
ParamTypeDescription
[optional] predicateObject.partialsearch predicate

Example

> await db.get();
[
    {id: 1, name: "johndoe", mail: "john@github.com"},
    {id: 2, name: "frankmass", mail: "frankmass@github.com"}
]

> await db.get({name: "johndoe"});
[ {id: 1, name: "johndoe", mail: "john@github.com"} ]

> await db.get({name: "stevejobs"});
[ ]

db.edit(predicate, data) ⇒ Promise<Object[]>

Edits data, given a search predicate object.

  • returns a list of edited occurences
ParamTypeDescription
predicateObject.partialsearch predicate
dataObject.partialdata that will replace found occurences key/values

Example

> await db.edit({name: "johndoe"}, {mail: "john@gitlab.com"});
[{1, "johndoe", "john@gitlab.com"}]

db.add(data) ⇒ Promise<Object[]>

Adds data (single object or array) to CSV.

  • returns created occurences
ParamTypeDescription
dataObject, Object[]data to be added

Example

> await db.add({id: 3, name: "stevejobs", mail: "jobs@github.com"});
[{id: 3, name: "stevejobs", mail: "jobs@github.com"}]

db.delete(predicate) ⇒ Promise<Object[]>

Deletes all data that matches the given predicate.

  • returns deleted occurences
ParamTypeDescription
predicateObject.partialsearch predicare

Example

> await db.delete({id: 1});
[ {id: 1, name: "johndoe", mail: "john@github.com"} ]

Local installation

Clone the project :

$ git clone https://github.com/ysnglt/node-csvdb

This project is made using Typescript. To generate the transpiled npm package, you need to run gulp :

$ gulp

You can run the full test suite with mocha :

$ npm i && npm run test

Keywords

csv

FAQs

Package last updated on 29 Jan 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