{"id":23276241,"url":"https://github.com/dinoscapeprogramming/database-package","last_synced_at":"2025-04-06T11:45:00.881Z","repository":{"id":58573805,"uuid":"532519117","full_name":"DinoscapeProgramming/Database-Package","owner":"DinoscapeProgramming","description":"A package you can use to create a JSON Database","archived":false,"fork":false,"pushed_at":"2022-09-07T17:22:13.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T01:36:31.769Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DinoscapeProgramming.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":"2022-09-04T11:25:01.000Z","updated_at":"2022-09-07T17:21:52.000Z","dependencies_parsed_at":"2023-01-17T23:01:15.338Z","dependency_job_id":null,"html_url":"https://github.com/DinoscapeProgramming/Database-Package","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/DinoscapeProgramming%2FDatabase-Package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FDatabase-Package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FDatabase-Package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FDatabase-Package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DinoscapeProgramming","download_url":"https://codeload.github.com/DinoscapeProgramming/Database-Package/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478251,"owners_count":20945262,"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-12-19T21:30:01.658Z","updated_at":"2025-04-06T11:45:00.863Z","avatar_url":"https://github.com/DinoscapeProgramming.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database Package\n\n## Documentation\n### Setup\n```js\nconst db = require('db.json');\nconst Database = new db.Database({\n  name: \"My Database\", // the name of your database\n  type: \"object\", // the type of your database: object or array\n  folder: \"./databases\" // the folder where your database files are stored\n});\n```\n\n### Use environment file to setup\n```js\nconst db = require('db.json');\nlet Database;\ndb.convertToEnvironmentObject({\n  path: \"./environment.txt\" // the environment file where your options are stored\n}).then((result) =\u003e {\n  Database = new db.Database(result.object);\n});\n```\n\n### Files\n##### Get file by index\n```js\nlet file;\nDatabase.files().then((files) =\u003e{\n  file = files[0 /*index of your file*/]\n});\n```\n\n##### Get file by name\n```js\nlet file;\nDatabase.files().then((files) =\u003e {\n  file = files.find((file) =\u003e file.name === \"database.json\" /*Name of your file*/);\n});\n```\n\n##### Get whole database\n```js\nfile.read().then((content) =\u003e {\n  console.log(content.data /*newest data in file*/ || file.content /*value when the files were defined*/);\n});\n```\n\n##### Object databases\n###### Set key to value\n```js\nfile.set(\"foo\" /*key*/, \"bar\" /*value*/).then((result) =\u003e {\n  console.log(result);\n});\n```\n\n###### Remove key\n```js\nfile.remove(\"foo\" /*key*/).then((result) =\u003e {\n  console.log(result);\n});\n```\n\n###### Get key\n```js\nfile.get(\"foo\" /*key*/).then((result) =\u003e {\n  console.log(result.value);\n});\n```\n\n#### Array databases\n###### Add value\n```js\nfile.add(\"Hello World\" /*value*/).then((result) =\u003e {\n  console.log(result);\n});\n```\n\n###### Set index to value\n```js\nfile.set(2 /*index*/, \"db.json\" /*value*/).then((result) =\u003e {\n  console.log(result);\n});\n```\n\n###### Remove index\n```js\nfile.remove(2, /*index*/).then((result) =\u003e {\n  console.log(result);\n});\n```\n\n###### Get index\n```js\nfile.get(1 /*index*/).then((result) =\u003e {\n  console.log(result.value);\n})\n```\n\n## Synchronous Documentation\n### Setup\n```js\nconst db = require('db.json');\nconst Database = new db.Database({\n  name: \"My Database\", // the name of your database\n  type: \"object\", // the type of your database: object or array\n  folder: \"./databases\" // the folder where your database files are stored\n  synchronous: true // make your database synchronous\n});\n```\n\n### Use environment file to setup\n```js\nconst db = require('db.json');\nconst Database = new db.Database(db.convertToEnvironmentObjectSync({\n  path: \"./environment.txt\" // the environment file where your options are stored\n}));\n```\n\n### Files\n##### Get file by index\n```js\nconst file = Database.files()[0 /*index of your file*/]\n```\n\n##### Get file by name\n```js\nconst file = Database.files().find((file) =\u003e file.name === \"database.json\" /*Name of your file*/);\n```\n\n##### Get whole database\n```js\nconsole.log(file.read().data || file.content);\n```\n\n##### Object databases\n###### Set key to value\n```js\nconsole.log(file.set(\"foo\" /*key*/, \"bar\" /*value*/));\n```\n\n###### Remove key\n```js\nconsole.log(file.remove(\"foo\" /*key*/));\n```\n\n###### Get key\n```js\nconsole.log(file.get(\"foo\" /*key*/));\n```\n\n#### Array databases\n###### Add value\n```js\nconsole.log(file.add(\"Hello World\" /*value*/));\n```\n\n###### Set index to value\n```js\nconsole.log(file.set(2 /*index*/, \"db.json\" /*value*/));\n```\n\n###### Remove index\n```js\nconsole.log(file.remove(2, /*index*/));\n```\n\n###### Get index\n```js\nconsole.log(file.get(1 /*index*/).value);\n```\n\n## Todo\n- There are currently no todos\n\n## Disclaimer\nThis package is mainly promise based but also contains a synchronous function for each function. If you're using a class to register a database it will call the asynchronous version and return the result synchronously.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinoscapeprogramming%2Fdatabase-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdinoscapeprogramming%2Fdatabase-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinoscapeprogramming%2Fdatabase-package/lists"}