{"id":16931630,"url":"https://github.com/romelperez/prhone-mdb","last_synced_at":"2026-05-04T01:32:54.466Z","repository":{"id":57330260,"uuid":"53100562","full_name":"romelperez/prhone-mdb","owner":"romelperez","description":"Mini database for examples and testing","archived":false,"fork":false,"pushed_at":"2017-03-06T22:34:24.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-23T15:49:41.501Z","etag":null,"topics":["database","mini-database"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romelperez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-04T02:20:28.000Z","updated_at":"2020-03-04T23:07:27.000Z","dependencies_parsed_at":"2022-09-21T02:02:35.215Z","dependency_job_id":null,"html_url":"https://github.com/romelperez/prhone-mdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/romelperez/prhone-mdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-mdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-mdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-mdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-mdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romelperez","download_url":"https://codeload.github.com/romelperez/prhone-mdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-mdb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260089912,"owners_count":22957151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","mini-database"],"created_at":"2024-10-13T20:44:24.704Z","updated_at":"2026-05-04T01:32:49.444Z","avatar_url":"https://github.com/romelperez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PRHONE MDB\n\n[![npm version](https://badge.fury.io/js/prhone-mdb.svg)](https://badge.fury.io/js/prhone-mdb)\n[![Build Status](https://travis-ci.org/romelperez/prhone-mdb.svg?branch=master)](https://travis-ci.org/romelperez/prhone-mdb)\n[![prhone](https://img.shields.io/badge/prhone-project-1b38a9.svg)](http://romelperez.com)\n\n\u003e PRHONE Mini-DataBase.\n\nMini-database manager using Node file system API in a relational way for simple storing or for practicing Node web servers without using a real DBMS.\n\n- Promises are used to handle operations.\n- Uses a JSON file to store the data.\n- All data is stored in tables.\n- The identifier of each item in each table is an UUID v4 and its name is `id`.\n- UTF8 is used for encoding.\n- When creating a new item:\n  - If table does not exists, it's created automatically.\n- When getting:\n  - Returns an empty array if table is not found.\n  - But error if fetching an unique item and it's not found.\n- When removing:\n  - If item does not exists, will be ok.\n- In all cases, if JSON file is corrupt, an error will be returned.\n\n## Install\n\n```bash\nnpm install --save prhone-mdb\n```\n\n## Use\n\n### `__dirname/database.json`\n\nEmpty file.\n\n### `__dirname/app.js`\n\n```js\nconst MDB = require('prhone-mdb');\n\nconst db = new MDB(`${__dirname}/database.json`);\n\n// Creates a new collection called `fruits` and create a new item within.\ndb.create('fruits', { name: 'apple', color: 'red' }).then(fruit =\u003e {\n  console.log('New fruit:', fruit);\n  // { id: 'c846482b-7dbe-4ee3-866c-e3cc06463cd2', name: 'apple', color: 'red' }\n}, err =\u003e {\n  console.log('Error:', err);  // If an error occurs.\n});\n\n// Create a new item in fruits collection.\ndb.create('fruits', { name: 'lemon', color: 'yellow' }).then(fruit =\u003e {\n  console.log('New fruit:', fruit);\n  // { id: '667ba0fd-dfc0-48aa-b8ab-17cd1fc5d48f', name: 'lemon', color: 'yellow' }\n}, err =\u003e {\n  console.log('Error:', err);\n});\n\ndb.getById('fruits', 'c846482b-7dbe-4ee3-866c-e3cc06463cd2').then(fruit =\u003e {\n  console.log('Fruit:', fruit);\n  // { id: 'c846482b-7dbe-4ee3-866c-e3cc06463cd2', name: 'apple', color: 'red' }\n});\n\ndb.\n  updateById('fruits', 'c846482b-7dbe-4ee3-866c-e3cc06463cd2', { color: 'green' }).\n  then(fruit =\u003e {\n    console.log('Modified fruit:', fruit);\n    // { id: 'c846482b-7dbe-4ee3-866c-e3cc06463cd2', name: 'apple', color: 'green' }\n  });\n\ndb.getById('fruits', 'c846482b-7dbe-4ee3-866c-e3cc06463cd2').then(fruit =\u003e {\n  console.log('Fruit:', fruit);\n  // { id: 'c846482b-7dbe-4ee3-866c-e3cc06463cd2', name: 'apple', color: 'green' }\n});\n```\n\n## API\n\n### `db MDB(String filePath)`\n\n- `String filePath` the absolute path to a JSON file where to store the data.\n\n### `Promise db.create(String tableName, Object item)`\n\n- `String tableName` The table name. Even if it does not exist.\n- `Object item` The new item to create in the table.\n\n#### `.then(function (Object item) {})`\n\n- `Object item` The new item created.\n\n### `Promise db.getById(String tableName, String itemId)`\n\n- `String tableName` The table name.\n- `String itemId` The item id.\n\n#### `.then(function (Object item) {})`\n\n- `Object item` The item fetched.\n\n### `Promise db.getAll(String tableName)`\n\n- `String tableName` The table name.\n\n#### `.then(function (Array items) {})`\n\n- `Array items` The collection of all items. If table did not exist, it is an empty array.\n\n### `Promise db.updateById(String tableName, String itemId, Object data)`\n\n- `String tableName` The table name.\n- `String itemId` The item id.\n- `Object data` The new data of the item. This will be merged.\n\n#### `.then(function (Object item) {})`\n\n- `Object item` The item updated.\n\n### `Promise db.removeById(String tableName, String itemId, Object data)`\n\n- `String tableName` The table name.\n- `String itemId` The item id.\n\n#### `.then(function () {})`\n\nThe promise will not give parameters.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromelperez%2Fprhone-mdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromelperez%2Fprhone-mdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromelperez%2Fprhone-mdb/lists"}