{"id":16906587,"url":"https://github.com/rsms/node-fsdocs","last_synced_at":"2025-09-14T15:57:19.796Z","repository":{"id":66105799,"uuid":"1326244","full_name":"rsms/node-fsdocs","owner":"rsms","description":"Simple, ACID and versioned file-system based document database","archived":false,"fork":false,"pushed_at":"2011-02-04T00:01:52.000Z","size":256,"stargazers_count":25,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T12:41:53.254Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rsms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-02-03T23:44:10.000Z","updated_at":"2022-06-20T12:30:50.000Z","dependencies_parsed_at":"2023-02-19T22:35:15.807Z","dependency_job_id":null,"html_url":"https://github.com/rsms/node-fsdocs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fnode-fsdocs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fnode-fsdocs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fnode-fsdocs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsms%2Fnode-fsdocs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsms","download_url":"https://codeload.github.com/rsms/node-fsdocs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248429952,"owners_count":21101924,"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-10-13T18:43:26.699Z","updated_at":"2025-04-11T15:26:54.723Z","avatar_url":"https://github.com/rsms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fsdocs\n\nSimple, [ACID](http://en.wikipedia.org/wiki/ACID) and versioned\nfile system-based document database for [node.js](http://nodejs.org/).\n\nThe idea is that you can use this simple, single-file module for quick hacks\nwhere installing (and possibly deploying) a full-scale \"real\" database like CouchDB, MySQL, Redis, MongoDB, etc kills your creativity. Since documents and their different versions are stored as regular JSON files, inspecting and manipulating data while developing is really easy and simple (just remove/edit/add files).\n\nPerformance is actually pretty good since the kernel will take care of caching\nthe most frequently read documents in memory. Also, even though this is ACID and\nall, a \"put\" only implies writing a single file. Atomicity and \"crashability\" is\nacquired through a mix of `link(2)` and `rename(2)` operations.\n\n## Example\n\n    var FSDocs = require('fsdocs').FSDocs\n    var docs = new FSDocs('./mydocs')\n\n    docs.put('doc1', {title:\"Hello\"}, function(err, ok) {\n      if (err) throw err\n      console.log(ok? 'stored ok' : 'conflict')\n      docs.get('doc1', function(err, document) {\n        if (err) throw err\n        console.log(document)\n      })\n    })\n\nOutput:\n\n    stored ok\n    { title: 'Hello', _version: 1 }\n\n## API\n\n### new FSDocs(location) -\u003e [object FSDocs]\n\nA document store based in directory at `location`\n\n#### docs.get(key, [version], [callback(err, document)])\n\nRetrieve a document. If `version` is omitted or less than 1, the most\nrecent version of the document is returned.\n\n#### docs.getSync(key, [version]) -\u003e document\n\nSynchronous version of `docs.get`\n\n#### docs.put(key, document, [callback(err, storedOk)])\n\nCreate or update a document. If `document` does not contain a `_version`\nmember or its `_version` member is less than 1, the document is\nconsidered as \"new\" and thus if there's already an existing version an\nerror will be returned (since the document is effectively version 1). If\nthere's a conflict when writing the new version, `storedOk` will be a\nfalse value. In this case it's up to the client to proceed (e.g. merge,\ndiscard, retry, etc). `document` must be an object.\n\n#### docs.putSync(key, document) -\u003e storedOk\n\nSynchronous version of `docs.put`\n\n\n## Implementation\n\nWhen writing a new document version to the database, fsdocs takes a rather simplistic approach in order to achieve [ACID](http://en.wikipedia.org/wiki/ACID)-ness:\n\n1. The new document is written to a temporary file. If this operation fails, we remove the temporary file and bail with an error.\n\n2. A (hard) link is created at \"key/lock\" (unique to the document key, not considering version). If this operation fails, another version is already being written which indicates a conflict and thus we bail with an error.\n\n3. A new link is created for the document data \"key/version.json\". If this operation fails, the document has already been modified (version exists) and thus we bail with an error.\n\n4. Finally the temporary link is renamed to \"key/current.json\". Because of the success of 2. and 3. we are guaranteed to upgrade the document to its latest version. We also retain atomicity because of the implementation of rename(), making concurrent reads of the \"current\" version safe.\n\nWe remove the \"key/lock\" file (unless 2. fails) when done with 3 or 4.\n\nMost file systems are in fact highly optimized \"key-value stores\", in a way.\n\n\n## Known issues\n\n- If the program crashes during writing a document the lockfile might not get\n  cleaned up, thus causing that document to become read-only (since any put\n  operation will fail to acquire the lockfile). In cases where there's only one\n  process manipulating the documents (or more specifically; only one process\n  manipulating a given key), this could be solved by simply adding the PID as\n  a suffix of the lockfile.\n\n\n## MIT license\n\nCopyright (c) 2011 Rasmus Andersson \u003chttp://rsms.me/\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsms%2Fnode-fsdocs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsms%2Fnode-fsdocs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsms%2Fnode-fsdocs/lists"}