{"_id":"@brillout/proto-db","_rev":"2-2129b99159a193149bcd6ea88ca10753","name":"@brillout/proto-db","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@brillout/proto-db","version":"0.1.0","scripts":{"docs":"mdocs"},"dependencies":{"@brillout/assert":"^0.1.0","fs-extra":"^8.1.0"},"devDependencies":{"@brillout/mdocs":"^0.1.30"},"repository":{"type":"git","url":"git+https://github.com/brillout/proto-db.git"},"publishConfig":{"access":"public"},"gitHead":"6f71d00ea646e0940478baf145a9407905c6e0b1","description":"<!---","bugs":{"url":"https://github.com/brillout/proto-db/issues"},"homepage":"https://github.com/brillout/proto-db#readme","_id":"@brillout/proto-db@0.1.0","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-rcu5xtikAOEd89AjhJK9dxL2vU/9VvMxKYWp0q1bScovlRCiwV07mWjaXEiZlxDFvUjYanYjw8Q80JTfN9cyJw==","shasum":"28aa9992ed12a32ef52c64f8944833efac0a4daf","tarball":"https://registry.npmjs.org/@brillout/proto-db/-/proto-db-0.1.0.tgz","fileCount":4,"unpackedSize":7307,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdq1IPCRA9TVsSAnZWagAA76gP/jab00YhKe53Tu9Tx8SF\nJmo0Kxbn63vuEMN1HmJIHRFWCnuK3mEhBjeIlEcw3UJnl7qGoishw/rQEfSq\n0lEHInvEkUZqej1KhsUZ/tGGgLGvV5ymdhxzwFJ7Ddr5frwr9UUpR3YFX8mO\n6rOJr2L86hDJRyV7jKa2IGNlAQ9h8gqLuKZpiye+A/HS+VsYrCcPw3vQJzwH\nx3INXoLCl7/DGux0PzAIKemVrCQ94iqqlnCF/vJqSPF7UikjHn0FLUdx+XX1\nIwqvTyQUH2xB/b1tCxlyHEaH75KGGpIK9M8Am3R0+wRz1xeGTzCRlkcff9o9\nwezyECDLtrPIxEDarXR9i8jVzqbga+/cw9rGkotmdbSiExMn9kCA8X26Igcg\nKbtgQq7iNGZtoz36NKrk/3MejKNN83lnvqE0tKM9VymFCadE+GAUMe0QbM6D\nMjqDOUyLOqT1mH6aDBfnlQQmwKSysQosbg1OQhcx46tzKwf5jetWiJ/bBT4f\niiIRiUGDk1WYUOLx3gXMWDwSna5XY8sBpa2Flt3tn0358bMcE/NpTz+5b57V\niwunR8h+OIgjv8z9dgUd/k+Jzm7xYVzHJ/aBdvLO6RTFm/NqTTZdFQxCBpDR\ndrLQufKmazJPuq83oj6vWhj18GIBD3zpQFzTeiXVCU8npPtKzBMvo+Gs04bV\n/67a\r\n=tzYo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC7N4CCY7CgqtmnyfGN/+JOO/dzHHWXugiDExpOgIWIigIhAN8ygpHLF5RWZ4KkMvKoOD5qliRc9Clbajy35K2sMNa+"}]},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"_npmUser":{"name":"brillout","email":"npm@brillout.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/proto-db_0.1.0_1571508751215_0.4784500122868245"},"_hasShrinkwrap":false},"0.1.1":{"name":"@brillout/proto-db","version":"0.1.1","scripts":{"docs":"mdocs"},"dependencies":{"@brillout/assert":"^0.1.0"},"devDependencies":{"@brillout/mdocs":"^0.1.30"},"repository":{"type":"git","url":"git+https://github.com/brillout/proto-db.git"},"publishConfig":{"access":"public"},"gitHead":"b14b0d40c0a71d93f7cd83899c9256d3198e00e3","description":"<!---","bugs":{"url":"https://github.com/brillout/proto-db/issues"},"homepage":"https://github.com/brillout/proto-db#readme","_id":"@brillout/proto-db@0.1.1","_nodeVersion":"16.5.0","_npmVersion":"7.20.5","dist":{"integrity":"sha512-vRIB+f19NH3gEyiIBM/GxZvK6AgS2I+DNvCt9abYKJmMmTHIxXaou5grtj6u3i7FsZnD1wSmWWiuaV/3VpLJTQ==","shasum":"7ec358f0e75c200e783002237e3468147c0948a7","tarball":"https://registry.npmjs.org/@brillout/proto-db/-/proto-db-0.1.1.tgz","fileCount":5,"unpackedSize":13987,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiDPxNCRA9TVsSAnZWagAAzokP+wX8bRu3zwPOSBU8VAxq\nJ0ItDSLbMqxtaZcjOub0zMb3bVYD37Kvz31T85BZkxax6VGLj73btctmFEXj\nKVL0yraYl5hHi9q47M9yIJri8apdSj6UpKDajxLlXenN0BHqyuiDL1bEY7EM\nCKXv5T796TpJWZ2B0nErbhkNlIcuspgAk3SJ/EIO6u3gbcwKZqcI6GLJDGuE\niIDtQRyjadibr7M4+ZUUr1bTzJsU1K0ERJpbMAXzgGQy4KwAq/TthOKoHTIH\nlWCihEXEiiPkICVmvbN6cIe8k7uAgiWLRpcGLwf9nuRvmmWqNi9moAOzXUOU\n9tvn62lh6rxlRbr9OCyQlQ4Fw8zfH8QfCJPpN5AAMHMmcv6cvF1aNJC1t4jY\n4ICkYzrpftRkCmHyO9BXdlUO+uIYM9Og9uUOgzWWcTYd2B01NzkyXZnmH04O\n7VXWuwybi+7PYPuUbp/QEdqIP14Bs6Pe3DzkHTOOK+gfo4vZCxOA0B+dIGQU\n1gpuM20zsSTB3rwlB+CTeFJqS5+k8PxE7pHQtaRxLTpuCEKPjv1IMfv7x4Gc\neFeOTB1v4GjICa2WnMR+IQKWY6SiQEBEkDAEOqP0wxn5c1bgfVKtePbGHJb6\n/iodzo6H3WYVOWAcIFNeKfag4tWOQdQywe67+levxX0N4nwN6FeOApGMFGo0\noyLO\r\n=QUD3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCPm3h9jWH6OB8I6zme14pk1SLB8PsyC5PBrZrVqWLV5gIgSh7yPgGzP9Pv9XeZJgdJ6GLQ3XOYZX1eXZGKS3yqUnQ="}]},"_npmUser":{"name":"brillout","email":"npm@brillout.com"},"directories":{},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/proto-db_0.1.1_1645018189877_0.9539113148121097"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-19T18:12:30.996Z","0.1.0":"2019-10-19T18:12:31.353Z","modified":"2022-04-04T20:41:34.555Z","0.1.1":"2022-02-16T13:29:49.978Z"},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"description":"<!---","homepage":"https://github.com/brillout/proto-db#readme","repository":{"type":"git","url":"git+https://github.com/brillout/proto-db.git"},"bugs":{"url":"https://github.com/brillout/proto-db/issues"},"readme":"<!---\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n-->\n# ProtoDB\n\n<p align='center'>\n<a href=\"#what-is-protodb\">What is ProtoDB</a>\n&nbsp; | &nbsp;\n<a href=\"#why-protodb\">Why ProtoDB</a>\n&nbsp; | &nbsp;\n<a href=\"#usage\">Usage</a>\n&nbsp; | &nbsp;\n<a href=\"#api\">API</a>\n</p>\n\n### What is ProtoDB\n\nProto is a small Node.js tool to persist a JavaScript object to disk.\n\n### Why ProtoDB\n\nAt the early prototyping phase of several projects,\nwe were too lazy to set up a proper database and\ninstead we used a JavaScript object and persisted it by reading & writing JSON to disk.\n\nWe expected that our approach wouldn't survive long\nand that we would soon need to replace our lazy hack with a real database.\nBut, and to our biggest surprise, we got quite far until we had to use a real database.\n\nProto is only ~40 lines of code ([/index.js](/index.js)),\nso you can easily modify it and write your own implementation.\n\nWe actually encourage you to write your own implementation;\nProtoDB is a cheering message that the technique of using JSON and the filesystem can be a great alternative to a database for prototypes and small to medium-sized apps.\nYou may not use Proto but you may want to consider this technique.\n\n\n### Usage\n\nIdiomatic usage example:\n\n~~~js\n// /example/db/index.js\n\nconst proto = require('@brillout/proto-db'); // npm install @brillout/proto-db\n\nconst data = proto.load(__dirname+'/data.json', {todos: []});\n\nmodule.exports = {createTodo, getAllTodos};\n\nasync function createTodo({text}) {\n  const id = proto.getUUID();\n  const newTodo = {id, text};\n\n  data.todos.push(newTodo);\n\n  await data._save();\n}\n\nfunction getAllTodos() {\n  return data.todos;\n}\n~~~\n~~~js\n// /example/index.js\n\nconst db = require('./db');\n\nrun();\n\nasync function run() {\n  await db.createTodo({text: 'Buy Milk'});\n\n  const todos = db.getAllTodos();\n  console.log(todos);\n}\n~~~\n\nWhich prints:\n~~~shell\n$ node example/\n[ { id: 430557952207, text: 'Buy Milk' } ]\n~~~\n\nThe new todo item is saved as JSON in `data.json`:\n~~~shell\n$ cat example/db/data.json\n{\"todos\":[{\"id\":199451513185,\"text\":\"Buy Milk\"}]}\n~~~\n\n### API\n\n- `const data = proto.load(databaseFile, defaultValue)` loads and returns the JavaScript object saved at `databaseFile`. If there is no file at `databaseFile` then `defaultValue` is used. The `proto.load` function is synchronous.\n- `await data._proto.save()` saves `data` to the disk at the path `databaseFile` you provided when running `const data = proto.load(databaseFile)`.\n- `proto.getUUID()` generates and returns a universally unique ID.\n\n<!---\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n\n\n\n\n\n\n    WARNING, READ THIS.\n    This is a computed file. Do not edit.\n    Instead, edit `/readme.template.md` and run `npm run docs` (or `yarn docs`).\n\n\n\n\n\n\n-->\n","readmeFilename":"readme.md"}