{"id":27102171,"url":"https://github.com/gugocharade/electron-data-holder","last_synced_at":"2025-04-06T15:19:34.996Z","repository":{"id":43558315,"uuid":"384770130","full_name":"gugocharade/electron-data-holder","owner":"gugocharade","description":"A simple way of storing data in electron app, save user data and app settings in simple steps","archived":false,"fork":false,"pushed_at":"2024-10-14T20:01:06.000Z","size":26,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T16:40:35.584Z","etag":null,"topics":["electron","javascript","json","nodejs"],"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/gugocharade.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":"2021-07-10T18:58:37.000Z","updated_at":"2024-10-14T20:01:09.000Z","dependencies_parsed_at":"2022-08-29T04:01:55.758Z","dependency_job_id":null,"html_url":"https://github.com/gugocharade/electron-data-holder","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/gugocharade%2Felectron-data-holder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gugocharade%2Felectron-data-holder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gugocharade%2Felectron-data-holder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gugocharade%2Felectron-data-holder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gugocharade","download_url":"https://codeload.github.com/gugocharade/electron-data-holder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276098,"owners_count":20912287,"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":["electron","javascript","json","nodejs"],"created_at":"2025-04-06T15:19:34.500Z","updated_at":"2025-04-06T15:19:34.988Z","avatar_url":"https://github.com/gugocharade.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/gugocharade"],"categories":[],"sub_categories":[],"readme":"# electron-data-holder\n\n\u003e `A simple way of storing data in electron app, save user data and app settings in simple steps.`\n\nTrying to persist data in the electron app is not an option since it doesn't have a built-in way of doing it, also it's a headache trying to implement it yourself.\n\nThat's why this module exists, the data is saved in a JSON file named data.json but you can change the name to whatever you want for example config.json to store user preferences.\n\nThe path to the JSON file is `app.getPath('userData')` or you can specify your preferred path.\n\nYou can store multiple files each one with a preferred name and also you can specify if you want to encrypt the data or not, the data is watched and saved after every change.\n\n# Install\n\n```js\n$ npm install electron-data-holder\n```\n\n# Usage\n\n### Step 1 :\n\nIn the main process call `initDB()`, this function accepts a configuration object with 2 properties:\n\n- key : `string` `(not required)` : the encryption key must be 32 characters long\n- customPath : `string` `(not required)` : The path to the folder where you want to store the JSON files.\n\n```js\nconst { initDB } = require('electron-data-holder');\n\n// the encryption key must be 32 characters long.\n\ninitDB({ key: 'the-encryption-key', customPath: 'the-path-to-the-folder' });\n\n// pass null instead of the key if you don't wan't to pass it but you want to pass a folder path;\n```\n\nThe 2 parameters are not required, if you didn't pass an encryption key the data won't be encrypted and if you didn't pass a folder path, the folder will be `app.getPath('userData')`.\n\n### Step 2 :\n\nIn the rendrer call `storeDB()`, this function accepts 2 parameters :\n\n- Data object : `object` `(required)` : The data must be an object.\n- Configuration object : `(not required)` : accepts 2 properties :\n  - fileName : `string`: The name is a string and without the `.json` part the default is `data.json`.\n  - encryption : `boolean` : whether you want the data to be encrypted or not, the default is ` false`.\n\n```js\nconst { storeDB } = require('electron-data-holder');\n\n// This function will returns a proxy with your data in it in order to watch the changes and update the JSON file.\n\nconst data = storeDB(\n  {\n    user: {\n      firstName: 'Elon',\n      lastName: 'Mask',\n    },\n    hobbies: ['learning', 'codding'],\n  },\n\n  {\n    fileName: 'dataFile',\n    encryption: true,\n  }\n);\n\n// you can create multiple files by giving each one a different name\n\nconst config = storeDB(\n  {\n    darkMode: true,\n    fontSize: 16,\n    fontFamily: ['Courier', 'Courier', 'Everson Mono'],\n  },\n\n  { fileName: 'config' }\n);\n```\n\nWhen the app is launched, it will search for the JSON files and get the data from them if they exist and return it, if not it will use the object you passed as the first parameter.\n\nAfter writing these lines of code, you are now ready to work on your app without worrying about the data, and the beautiful thing is that there is no APIs to insert or get the data, use your data as you would do in vanilla javascript.\n\n# Manipulating data\n\nLet's use this example:\n\n```js\nconst { storeDB } = require('electron-data-holder');\n\nconst data = storeDB(\n  {\n    user: {\n      firstName: 'Elon',\n      lastName: 'Mask',\n    },\n    hobbies: ['learning', 'coding'],\n  },\n\n  {\n    fileName: 'dataFile',\n    encryption: true,\n  }\n);\n```\n\n## Reading data\n\nLet's log to the console the first element in the hobbies array:\n\n```js\nconsole.log(data.hobbies[0]); // 'learning'\n```\n\n## Modifying data\n\nLet's add \"gaming\" to the hobbies array:\n\n```js\ndata.hobbies.push('gaming');\n\nconsole.log(data.hobbies); // Proxy {0: \"learning\", 1: \"coding\", 2: \"gaming\"}\n```\n\nLet's add an \"age\" property to the user object:\n\n```js\ndata.user.age = 47;\n\nconsole.log(data.user); // Proxy {firstName: \"Elon\", lastName: \"Mask\", age: 47}\n```\n\nThe `storeDB()` function returns a proxy with your data in it in order to watch the changes and update the JSON file.\nEvery time you modify your data the JSON file will be updated accordingly.\n\nAs you can see there is no extra stuff for reading and modifying your data and also you don't need to worry about saving it in every change, this package will handle everything for you so you can focus on building your app. HAPPY CODING\n\n# Donation\n\nIf you found this package useful support me.\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/gugocharade)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgugocharade%2Felectron-data-holder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgugocharade%2Felectron-data-holder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgugocharade%2Felectron-data-holder/lists"}