├── .gitignore
├── .travis.yml
├── LICENSE
├── gulpfile.js
├── package.json
├── readme.md
├── src
├── csv-editor
│ ├── index.ts
│ └── types.ts
├── database
│ ├── crud
│ │ ├── create.ts
│ │ ├── delete.ts
│ │ ├── read.ts
│ │ └── update.ts
│ ├── index.ts
│ └── init.ts
├── index.ts
└── utils.ts
├── test
└── index.ts
├── tsconfig.json
└── tslint.json
/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 | /node_modules
3 | bin
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "node"
4 | - "7"
5 | - "8"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 ysnglt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | const gulp = require("gulp");
2 | const ts = require("gulp-typescript");
3 | const jeditor = require("gulp-json-editor");
4 | const del = require("del");
5 |
6 | const project = ts.createProject("tsconfig.json");
7 | const OUT_DIR = project.options.outDir;
8 |
9 | // clean build dir
10 | gulp.task("clean", () => del(["bin"]));
11 |
12 | // transpile project to JS using tsconfig.json
13 | gulp.task("compile", ["clean"], () => {
14 | project
15 | .src()
16 | .pipe(project())
17 | .pipe(gulp.dest(OUT_DIR));
18 | });
19 |
20 | // remove source utils from package and copies it to dist folder
21 | gulp.task("edit-package", ["clean"], () => {
22 | gulp
23 | .src("./package.json")
24 | .pipe(
25 | jeditor(json => {
26 | json.main = "index.js";
27 | delete json.scripts;
28 | delete json.devDependencies;
29 | return json;
30 | })
31 | )
32 | .pipe(gulp.dest(OUT_DIR));
33 | });
34 |
35 | gulp.task("copy-readme", ["clean"], () => {
36 | gulp.src("./readme.md").pipe(gulp.dest(OUT_DIR));
37 | });
38 |
39 | gulp.task("default", ["clean", "compile", "edit-package", "copy-readme"]);
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "csv-database",
3 | "version": "0.9.2",
4 | "description": "lightweight CSV database",
5 | "main": "src/index.ts",
6 | "keywords": [
7 | "csv",
8 | "database",
9 | "db",
10 | "crud",
11 | "storage",
12 | "flat file",
13 | "file"
14 | ],
15 | "repository": {
16 | "url": "https://github.com/ysnglt/node-csvdb"
17 | },
18 | "dependencies": {
19 | "fast-csv": "^2.4.1",
20 | "proper-lockfile": "^3.0.2",
21 | "tempy": "^0.2.1"
22 | },
23 | "devDependencies": {
24 | "@types/mocha": "^2.2.44",
25 | "@types/mock-fs": "^3.6.30",
26 | "@types/node": "^8.0.53",
27 | "@types/tempy": "^0.1.0",
28 | "del": "^3.0.0",
29 | "gulp": "^3.9.1",
30 | "gulp-json-editor": "^2.2.1",
31 | "gulp-typescript": "^3.2.3",
32 | "mocha": "^4.0.1",
33 | "mock-fs": "^4.4.2",
34 | "prettier": "^1.9.2",
35 | "ts-node": "^4.0.2",
36 | "tslint": "^5.8.0",
37 | "tslint-config-prettier": "^1.6.0",
38 | "typescript": "^2.6.2"
39 | },
40 | "scripts": {
41 | "prepare": "gulp",
42 | "test": "mocha -r ts-node/register test/index.ts",
43 | "lint": "tslint --project .",
44 | "format": "prettier --write {src,test}/**/*.ts"
45 | },
46 | "author": "ysnglt",
47 | "license": "MIT"
48 | }
49 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # csv-database : node.js CSV database
2 |
3 | Lightweight CRUD database, using CSV files as a storage.
4 |
5 | Features :
6 |
7 | * complete CRUD API with model validation
8 | * native JS objects manipulation
9 | * Typescript typings
10 | * concurrency-ready
11 |
12 | ## Usage
13 |
14 | ```js
15 | > const db = await csvdb("users.csv", ["id","name","mail"]);
16 |
17 | > await db.get({mail: "johndoe@github.com"});
18 | [ {id: 1, name: "johndoe", mail: "john@github.com"} ]
19 |
20 | > await db.add({id: 2, name: "stevejobs", mail: "jobs@github.com"});
21 | ```
22 |
23 | ## Installation
24 |
25 | `$ npm install csv-database`
26 |
27 | ## API Reference
28 |
29 | * [csvdb](#module_csvdb)
30 | * [.get](#module_csvdb.get)
31 | * [.edit](#module_csvdb.edit)
32 | * [.add](#module_csvdb.add)
33 | * [.delete](#module_csvdb.delete)
34 |
35 |
36 |
37 | ### csvdb(filename, model [, delimiter]) ⇒ `Promise`
38 |
39 | Returns a database, given a CSV file and its model.
40 |
41 | * `;` as default delimiter
42 | * file is created if it doesn't exist
43 |
44 | | Param | Type | Description |
45 | | -------------------- | ---------- | ---------------- |
46 | | filename | `string` | csv file |
47 | | model | `string[]` | database model |
48 | | [optional] delimiter | `string` | custom delimiter |
49 |
50 | **Example**
51 |
52 | ```js
53 | const db = await csvdb("users.csv", ["id","name","mail"], ",");
54 | ```
55 |
56 |
57 |
58 | ### db.get([predicate]) ⇒ `Promise