nodejs database using CSV files as storage
Lightweight CRUD database, using CSV files as a storage.
Features :
> const db = await csvdb("users.csv", ["id","name","mail"]);
> await db.get({mail: "[email protected]"});
[ {id: 1, name: "johndoe", mail: "[email protected]"} ]
> await db.add({id: 2, name: "stevejobs", mail: "[email protected]"});
$ npm install csv-database
Promise<CsvDatabase>
Returns a database, given a CSV file and its model.
;
as default delimiterParam | Type | Description |
---|---|---|
filename | string |
csv file |
model | string[] |
database model |
[optional] delimiter | string |
custom delimiter |
Example
const db = await csvdb("users.csv", ["id","name","mail"], ",");
Promise<Object[]>
Returns database content. If given a predicate, returns data that matches its key-values pairs.
Param | Type | Description |
---|---|---|
[optional] predicate | Object.partial |
search predicate |
Example
> await db.get();
[
{id: 1, name: "johndoe", mail: "[email protected]"},
{id: 2, name: "frankmass", mail: "[email protected]"}
]
> await db.get({name: "johndoe"});
[ {id: 1, name: "johndoe", mail: "[email protected]"} ]
> await db.get({name: "stevejobs"});
[ ]
Promise<Object[]>
Edits data, given a search predicate object.
Param | Type | Description |
---|---|---|
predicate | Object.partial |
search predicate |
data | Object.partial |
data that will replace found occurences key/values |
Example
> await db.edit({name: "johndoe"}, {mail: "[email protected]"});
[{1, "johndoe", "[email protected]"}]
Promise<Object[]>
Adds data (single object or array) to CSV.
Param | Type | Description |
---|---|---|
data | Object, Object[] |
data to be added |
Example
> await db.add({id: 3, name: "stevejobs", mail: "[email protected]"});
[{id: 3, name: "stevejobs", mail: "[email protected]"}]
Promise<Object[]>
Deletes all data that matches the given predicate.
Param | Type | Description |
---|---|---|
predicate | Object.partial |
search predicare |
Example
> await db.delete({id: 1});
[ {id: 1, name: "johndoe", mail: "[email protected]"} ]
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