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 ; > await db; id: 1 name: "johndoe" mail: "john@github.com" > await db;
Installation
$ npm install csv-database
API Reference
Promise<CsvDatabase>
csvdb(filename, model [, delimiter]) ⇒ Returns a database, given a CSV file and its model.
;
as default delimiter- file is created if it doesn't exist
Param | Type | Description |
---|---|---|
filename | string |
csv file |
model | string[] |
database model |
[optional] delimiter | string |
custom delimiter |
Example
const db = await ;
Promise<Object[]>
db.get([predicate]) ⇒ 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
Param | Type | Description |
---|---|---|
[optional] predicate | Object.partial |
search predicate |
Example
> await db; id: 1 name: "johndoe" mail: "john@github.com" id: 2 name: "frankmass" mail: "frankmass@github.com" > await db; id: 1 name: "johndoe" mail: "john@github.com" > await db;
Promise<Object[]>
db.edit(predicate, data) ⇒ Edits data, given a search predicate object.
- returns a list of edited occurences
Param | Type | Description |
---|---|---|
predicate | Object.partial |
search predicate |
data | Object.partial |
data that will replace found occurences key/values |
Example
> await db;1 "johndoe" "john@gitlab.com"
Promise<Object[]>
db.add(data) ⇒ Adds data (single object or array) to CSV.
- returns created occurences
Param | Type | Description |
---|---|---|
data | Object, Object[] |
data to be added |
Example
> await db;id: 3 name: "stevejobs" mail: "jobs@github.com"
Promise<Object[]>
db.delete(predicate) ⇒ Deletes all data that matches the given predicate.
- returns deleted occurences
Param | Type | Description |
---|---|---|
predicate | Object.partial |
search predicare |
Example
> await db; 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