{"id":13515333,"url":"https://github.com/CreaturePhil/origindb","last_synced_at":"2025-03-31T04:36:58.292Z","repository":{"id":36483334,"uuid":"40788911","full_name":"CreaturePhil/origindb","owner":"CreaturePhil","description":"Blazing fast and flexible JSON database.","archived":false,"fork":false,"pushed_at":"2017-01-02T08:04:10.000Z","size":52,"stargazers_count":24,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-14T03:33:48.016Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/origindb","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/CreaturePhil.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":"2015-08-15T22:28:20.000Z","updated_at":"2022-06-23T07:54:52.000Z","dependencies_parsed_at":"2022-08-25T05:00:58.248Z","dependency_job_id":null,"html_url":"https://github.com/CreaturePhil/origindb","commit_stats":null,"previous_names":["creaturephil/eosdb"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CreaturePhil%2Forigindb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CreaturePhil%2Forigindb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CreaturePhil%2Forigindb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CreaturePhil%2Forigindb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CreaturePhil","download_url":"https://codeload.github.com/CreaturePhil/origindb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246418657,"owners_count":20773934,"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":[],"created_at":"2024-08-01T05:01:09.670Z","updated_at":"2025-03-31T04:36:57.263Z","avatar_url":"https://github.com/CreaturePhil.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# OriginDB [![Build Status](https://travis-ci.org/CreaturePhil/origindb.svg?branch=master)](https://travis-ci.org/CreaturePhil/origindb) [![Dependency Status](https://david-dm.org/creaturephil/origindb.svg)](https://david-dm.org/creaturephil/origindb) [![devDependency Status](https://david-dm.org/creaturephil/origindb/dev-status.svg)](https://david-dm.org/creaturephil/origindb#info=devDependencies)\n\nBlazing fast and flexible JSON database.\n\n```js\ndb(key).set(property, value)\n```\n\nEach key in the `db` object **corresponds to a JSON file**.\n\nThis can also be view as:\n\n```js\ndb(file).set(property, value)\n```\n\n## Install\n\n```\n$ npm install origindb --save\n```\n\n## Usage\n\n```js\nvar db = require('origindb')('db');\ndb('money').set('phil', 10);\ndb('money').set('some_user', db('money').get('phil') + 10);\ndb('seen').set('some_user', Date.now());\ndb('posts').set('posts', [\n  { title: 'OriginDB is awesome!', body: '...', likes: 10 },\n  { title: 'flexbility ', body: '...', likes: 3 },\n  { title: 'something someting something', body: '...', likes: 8 }\n]);\n```\n\nIn the `db` **folder**:\n\n```json\n// money.json\n{\n  \"phil\": 10\n}\n\n// seen.json\n{\n  \"some_user\": 1439674925906\n}\n\n// posts.json\n{\n  \"posts\": [\n    { \"title\": \"OriginDB is awesome!\", \"body\": \"...\", \"likes\": 10 },\n    { \"title\": \"flexbility \", \"body\": \"...\", \"likes\": 3 },\n    { \"title\": \"something someting something\", \"body\": \"...\", \"likes\": 8 }\n  ]\n}\n```\n\n## API\n\n### db(databaseDirectory, options)\n\nCreate a new database.\n\nParameters:\n\n- ``databaseDirectory``: _String_ -\nThe folder where all the json files will be stored at when using the `files`\nadapter. Otherwise, it is the name of where the data will be stored at.\n- ``options`` - _Object_\n  - ``adapter`` - _String_ or _Function_. Defaults to `files`.\n\nReturns: Function(key)\n  - ``key``: _String_ - JSON file in the database directory\n  - Returns: _Object_ - Methods of OriginDB.\n\nExamples:\n\n```js\nvar db = require('origindb')('userdb');\n```\n\n```js\nvar db = require('origindb')('apidb');\n```\n\n```js\nvar db = require('origindb')('mongodb://localhost:27017/myproject', {adapter: 'mongo'});\n```\n\n### save()\n\nSaves the current data in the database to all files. Does not write to a file\nif no changes were made.\n\nParameters: None\n\nReturns: _undefined_\n\nExample:\n\n```js\n// main.js\ndb('money').object().phil = 25;\ndb.save();\n\n// money.json\n{\n  'phil': 25\n}\n```\n\n### get(property, defaultValue)\n\nGet a property and if it does not exist, return the default value instead.\n\nParameters:\n\n- ``property``: _String_ | _Array_\n- ``defaultValue``: _any_\n\nReturns: _any_ - Depends on what is in property.\n\nExample:\n\n```js\n// money.json\n{\n  'phil': 10,\n  'stevo': 5\n}\n\n// main.js\ndb('money').get('phil'); // 10\ndb('money').get('jared', 0); // 0\ndb('money').get('stevo', 0); // 5\n```\n\n```js\n// profile.json\n{\n  'phil': {\n    'name': 'Philip La',\n    'img': {\n      'width': 55,\n      'height': 20\n    }\n  }\n}\n\n// main.js\ndb('profile').get(['phil', 'name']); // 'Philip La'\ndb('profile').get(['phil', 'img', 'width']); // 55\ndb('profile').get(['phil', 'img', 'height'], 0); // 20\ndb('profile').get(['phil', 'img', 'resolution'], '4k'); // '4k'\ndb('profile').get(['phil', 'join_date']); // undefined\ndb('profile').get(['phil', 'img']); // { width: 55, height: 20 }\n```\n\n### has(property)\n\nChecks to see if it has a property.\n\nParameters:\n\n- ``property``: _String_ | _Array_\n\nReturns: _Boolean_\n\nExample:\n\n```js\n{\n  'bar': 'some kind of data',\n  'baz': 'some kind of data'\n}\n\nconsole.log(db('foo').has('bar'));\n//=\u003e true\nconsole.log(db('foo').has('boo'));\n//=\u003e false\n```\n\n### delete(property)\n\nDelete a property.\nShorthand for ``delete db('key').object()['prop']; db.save();``\n\nParameters:\n\n- ``property``: _String_ | _Array_\n\nReturns: _Object_ - Methods of OriginDB. This is useful for chaining methods\ntogether.\n\nExample:\n\n```js\n// food.json before\n{\n  'soup': true,\n  'noodle': true\n}\n\ndb('food').delete('soup');\n\n// food.json after\n{\n  'noodle': true\n}\n```\n\n### set(property, value)\n\nSet a property with a value. This method automatically saves.\n\nParameters:\n\n- ``property``: _String_ | _Array_\n- ``value``: _any_\n\nReturns: _Object_ - Methods of OriginDB. This is useful for chaining methods\ntogether.\n\nExamples:\n\n```js\n// main.js\ndb('money')\n  .set('phil', 10)\n  .set('josh', 89)\n  .set('mike', db.get('mike', 0))\n  .set('alex', 17);\n\n// money.json\n{\n  'phil': 10,\n  'josh': 89,\n  'mike': 0,\n  'alex': 17\n}\n```\n\n```js\ndb('tickets').set('phil', db('tickets').get('phil').concat[generateTicket()]);\n```\n\n```js\n// profile.json before\n{\n  'phil': {\n    'name': 'Steven Hausen',\n    'img': {\n      'width': 55,\n      'height': 20\n    }\n  }\n}\n\n// main.js\ndb('profile')\n  .set(['phil', 'name'], 'Steven Hausen')\n  .set(['phil', 'friends'], ['fender', 'a Gryphon'])\n  .set(['phil', 'wins', 'game_format'], 9)\n  .set(['phil', 'img', 'height'], 200);\n\n// profile.json after\n{\n  'phil': {\n    'name': 'Steven Hausen',\n    'img': {\n      'width': 55,\n      'height': 200\n    },\n    'friends': ['fender', 'a Gryphon'],\n    'wins': {\n      'game_format': 9\n    }\n  }\n}\n```\n\n### object()\n\nGet the JSON object to directly manipulate it.\n\nParameters: None\n\nReturns: _Object_\n\nExamples:\n\n```js\n// join_date.json\n{\n  'phil': 1450814470721,\n  'micheal': 1394814738429\n}\n\n// main.js\nvar name = 'phil';\nconsole.log(db('join_date').object()[name]); // 1450814470721\nconsole.log(db('join_date').object().micheal); // 1394814738429\ndb('join_date').object()[name] = new Date();\ndb.save();\n\n// join_date.json\n{\n  'phil': 1450815256685,  \n  'micheal': 1394814738429\n}\n```\n\n```js\n// money.js\n{\n  \"phil\": 10,\n  \"some_user\": 20,\n  \"john\": 10,\n  \"mike\": 23,\n}\n\n// main.js\nvar users = db('money').object();\nvar total = Object.keys(users).reduce(function(acc, cur) {\n  return acc + users[cur];\n}, 0);\n\nconsole.log(total); // 63\n```\n\n## Other methods\n\nSome other methods that are provided by lodash are:\n[keys](https://lodash.com/docs#keys),\n[transform](https://lodash.com/docs#transform),\n[values](https://lodash.com/docs#values), and\n[update](https://lodash.com/docs#update).\n\n## Adapters\n\nOriginDB defaults to `files` adapter which just uses files in a folder to store\nthe data. However, OriginDB supports other ways to store data.\n\nCurrent supported adapters are:\n\n- Files\n- MongoDB\n\n### MongoDB\n\nOriginDB stores data in MongoDB like this:\n\n```js\n// app.js\nvar db = require('origindb')('mongodb://localhost:27017/myproject', {adapter: 'mongo'});\ndb('money')\n  .set('phil', 10)\n  .set('some_user', db('money').get('phil') + 10);\ndb('seen').set('some_user', Date.now());\ndb('posts').set('posts', [\n  { title: 'OriginDB is awesome!', body: '...', likes: 10 },\n  { title: 'flexbility ', body: '...', likes: 3 },\n  { title: 'something someting something', body: '...', likes: 8 }\n]);\n\n// MongoDB\n{\n\t\"_id\" : ObjectId(\"567e4741b09bffce48aa98b1\"),\n\t\"name\" : \"money\",\n\t\"data\" : \"{\\\"phil\\\":10,\\\"some_user\\\":20}\"\n}\n{\n\t\"_id\" : ObjectId(\"567e4741b09bffce48aa98b2\"),\n\t\"name\" : \"seen\",\n\t\"data\" : \"{\\\"some_user\\\":1451116353687}\"\n}\n{\n\t\"_id\" : ObjectId(\"567e4741b09bffce48aa98b3\"),\n\t\"name\" : \"posts\",\n\t\"data\" : \"{\\\"posts\\\":[{\\\"title\\\":\\\"OriginDB is awesome!\\\",\\\"body\\\":\\\"...\\\",\\\"likes\\\":10},{\\\"title\\\":\\\"flexbility \\\",\\\"body\\\":\\\"...\\\",\\\"likes\\\":3},{\\\"title\\\":\\\"something someting something\\\",\\\"body\\\":\\\"...\\\",\\\"likes\\\":8}]}\"\n}\n```\n\nYou can also create your own adapters. For example, a adapter that does not save\nto file but instead does nothing.\n\n```js\nvar db = require('origindb')({\n  /**\n   * @param {String} name - name of location of where the data will be stored.\n   * @param {Object} objects - the internal in-memory cache object\n   * @param {Object} checksums - every key in objects' checksums\n   * @param {Object} options\n   * @return {Function} save function\n   */\n  adapter: function(name, objects, checksums, options) {\n    return function noopSave() {};\n  }\n});\n```\n\n## License\n\nMIT © [Phil](http://creaturephil.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCreaturePhil%2Forigindb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCreaturePhil%2Forigindb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCreaturePhil%2Forigindb/lists"}