{"_id":"@alinsme/electron-db","_rev":"1-dab7fc74158a4626bdf1afa020c9243c","name":"@alinsme/electron-db","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@alinsme/electron-db","version":"0.0.1","keywords":["electron","database","json database","json table","electron database","electron simple database"],"author":{"url":"https://github.com/alinme","name":"Alinsme","email":"npm@clerk.aleeas.com"},"license":"MIT","_id":"@alinsme/electron-db@0.0.1","maintainers":[{"name":"alinsme","email":"alinmoraru980@gmail.com"}],"homepage":"https://github.com/alinsme/electron-db#readme","bugs":{"url":"https://github.com/alinsme/electron-db/issues"},"dist":{"shasum":"2d9c7cc0786850b9dc257019ac1ccfe6bd16acc3","tarball":"https://registry.npmjs.org/@alinsme/electron-db/-/electron-db-0.0.1.tgz","fileCount":8,"integrity":"sha512-gf934f33HLtaimLjzemLA2igGayX8CqaHti7GUS+VWaFrtGuNc7foPhC3r7iO5qU6rSSC39JFVt3MMaW3blQNA==","signatures":[{"sig":"MEUCIQDndZMUoBJvAs7SVvVyfTU/23QJpVP4qlHysPgJSbkVcAIgM5cos/b4WH4FiMB0ES7oHd8bnQpWUWNMXosXcgbZ5co=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33942},"main":"index.js","gitHead":"51e80f2e8a6ac073090a9cac7e4ae8f34e6974d7","scripts":{"test":"node test.js","start":"node index.js"},"_npmUser":{"name":"alinsme","email":"alinmoraru980@gmail.com"},"repository":{"url":"git+https://github.com/alinsme/electron-db.git","type":"git"},"_npmVersion":"10.8.3","description":"Electron module that simulates database table operations which really just uses json file to store tables in the Application Folder.","directories":{},"_nodeVersion":"22.9.0","_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/electron-db_0.0.1_1730759550668_0.4168153896363327","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@alinsme/electron-db","version":"0.0.2","description":"Electron module that simulates database table operations which really just uses json file to store tables in the Application Folder.","main":"index.js","scripts":{"start":"node index.js","test":"node test.js"},"author":{"name":"Alinsme","email":"npm@clerk.aleeas.com","url":"https://github.com/alinme"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alinsme/electron-db.git"},"devDependencies":{},"keywords":["electron","database","json database","json table","electron database","electron simple database"],"bugs":{"url":"https://github.com/alinsme/electron-db/issues"},"homepage":"https://github.com/alinsme/electron-db#readme","_id":"@alinsme/electron-db@0.0.2","gitHead":"3484d30fc6546daf27c38bb00799373e72ad8e30","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-BzdNenaU1aNqrdv972E4fnNwa1Lt7NhhObtc8zMTxnB5mZ2Ua2ayQVbLAHzaTd3fHUeNaTCQ5rDRApjWzOonAg==","shasum":"3ec884cf7a84aaf94c7fc390a48b7c40819944b9","tarball":"https://registry.npmjs.org/@alinsme/electron-db/-/electron-db-0.0.2.tgz","fileCount":8,"unpackedSize":33907,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHOciweZmVoL5L0pf5jqUi6nIcKtLQCE1gywAskX4wrOAiEAh7zBN0Vha8IPJhBWuW9YlUdcCYVNZqgspsjWTIDkroE="}]},"_npmUser":{"name":"alinsme","email":"alinmoraru980@gmail.com"},"directories":{},"maintainers":[{"name":"alinsme","email":"alinmoraru980@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/electron-db_0.0.2_1730759866832_0.8531930561492729"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-04T22:32:30.554Z","modified":"2024-11-04T22:37:47.259Z","0.0.1":"2024-11-04T22:32:30.979Z","0.0.2":"2024-11-04T22:37:47.061Z"},"bugs":{"url":"https://github.com/alinsme/electron-db/issues"},"author":{"name":"Alinsme","email":"npm@clerk.aleeas.com","url":"https://github.com/alinme"},"license":"MIT","homepage":"https://github.com/alinsme/electron-db#readme","keywords":["electron","database","json database","json table","electron database","electron simple database"],"repository":{"type":"git","url":"git+https://github.com/alinsme/electron-db.git"},"description":"Electron module that simulates database table operations which really just uses json file to store tables in the Application Folder.","maintainers":[{"name":"alinsme","email":"alinmoraru980@gmail.com"}],"readme":"# electron-db\r\n---\r\n\r\n[![NPM version](https://img.shields.io/npm/v/electron-db.svg)](https://npmjs.org/package/electron-db \"View this project on NPM\")\r\n[![NPM downloads](https://img.shields.io/npm/dm/electron-db.svg)](https://npmjs.org/package/electron-db \"View this project on NPM\")\r\n> Flat file database solution for electron and other Nodejs apps.\r\n\r\n**electron-db** is an npm library that let you simplify database creation and operation on a json file.\r\n\r\nThe json file is saved on the application folder or you can specify the location for the database to be created. From version 0.10.0, the user has the option to save the database table anywhere they chose.\r\n\r\nThe only difference with the default location is that, the user have to pass the string location as the second argument to any function to be used (this is optional if you want to control the database location).\r\n\r\nThe table format contained in the `table_name.json` should be in the form of\r\n```\r\n{\r\n  \"table_name\": [\r\n    {\r\n      \"field1\": \"Value of field 1\",\r\n      \"field2\": \"Value of field 2\",\r\n      ...\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n**Important:** The script that uses this library should be run with electron command first in order to create the directory on the user data folder (when not using a custom directory for the database). The name that will be used for the app directory will be what was indicated in the `package.json` as <em>name</em>. If this is not set, the <em>name</em> property will be used.\r\n\r\n### **Installation**\r\nThe preferred way of installation is to install it locally on the application.\r\n```javascript\r\nnpm install @electron-db --save\r\n```\r\n\r\n### **Creating Table**\r\nCreates a json file `[table-name].js` inside the application `userData` folder.\r\n\r\nIn Windows, the application folder should be in `C:\\Users\\[username]\\AppData\\Roaming\\[application name]`\r\n\r\n```javascript\r\n\r\nconst db = require('electron-db');\r\nconst { app, BrowserWindow } = require(\"electron\");\r\n\r\ndb.createTable('customers', (succ, msg) => {\r\n  // succ - boolean, tells if the call is successful\r\n  console.log(\"Success: \" + succ);\r\n  console.log(\"Message: \" + msg);\r\n})\r\n\r\n/*\r\n\tOutput:\r\n    \tSuccess: true\r\n        Message: Success!\r\n\r\n\tResult file (customers.json):\r\n    {\r\n    \t\"customers\": []\r\n    }\r\n*/\r\n```\r\n\r\n### **Creating Table specifying the Location**\r\nThe custom location, if desired, shall be passed as the second argument and the remaining arguments are the same (if any) on a specific function.\r\n```javascript\r\nconst path = require('path')\r\n\r\n// This will save the database in the same directory as the application.\r\nconst location = path.join(__dirname, '')\r\n\r\ndb.createTable('customers', location, (succ, msg) => {\r\n  // succ - boolean, tells if the call is successful\r\n  if (succ) {\r\n    console.log(msg)\r\n  } else {\r\n    console.log('An error has occured. ' + msg)\r\n  }\r\n})\r\n```\r\n\r\n### **Inserting Object/Data to Table**\r\nInsert an object into the list of row/data of the table.\r\n\r\nTo insert to a custom location, pass the custom location as the second argument\r\nas shown in the sample above. But do not forget to check if the database is valid.\r\n\r\n```javascript\r\nlet obj = new Object();\r\n\r\nobj.name = \"Alexius Academia\";\r\nobj.address = \"Paco, Botolan, Zambales\";\r\n\r\nif (db.valid('customers')) {\r\n  db.insertTableContent('customers', obj, (succ, msg) => {\r\n    // succ - boolean, tells if the call is successful\r\n    console.log(\"Success: \" + succ);\r\n    console.log(\"Message: \" + msg);\r\n  })\r\n}\r\n\r\n/*\r\n\tOutput:\r\n    \tSuccess: true\r\n        Message: Object written successfully!\r\n\r\n    Result file (customers.json):\r\n    {\r\n      \"customers\": [\r\n        {\r\n          \"name\": \"Alexius Academia\",\r\n          \"address\": \"Paco, Botolan, Zambales\"\r\n        }\r\n      ]\r\n    }\r\n\r\n*/\r\n```\r\n\r\n### For the database table at custom location\r\nFor the implementation of this new feature, always put the location string as second argument for all the functions. (The directory string must end with appropriate slashes, forward slash for unix and back slash with escape string for Windows) (e.g. Windows: ```'C:\\\\databases\\\\'```, Unix: ```'/Users/<username>/Desktop/'```). For good practice, use the ```path.join``` method to let the OS apply its directory separator automatically.\r\n\r\n<!--\r\n### **Inserting Multiple Objects/Data to Table**\r\nInsert multiple objects into the list of row/data of the table.\r\n\r\n```javascript\r\nconst db = require('electron-db');\r\n\r\nconst arr = ['product_1', 'product_2', 'product_3', 'product_4', 'product_5'];\r\n\r\nconst m = arr.map((product, id) => {\r\n  const obj = {}\r\n  obj.image_name = product;\r\n  obj.index = id;\r\n\r\n  return obj;\r\n});\r\n\r\ndb.insertTableContents('records', m, (isSuccess, message) => {\r\n  console.log(isSuccess);\r\n  console.log(message);\r\n});\r\n\r\n/*\r\n\tOutput:\r\n    \ttrue\r\n      Object written successfully!\r\n      true\r\n      Object written successfully!\r\n      true\r\n      Object written successfully!\r\n      true\r\n      Object written successfully!\r\n      true\r\n      Object written successfully!\r\n*/\r\n```\r\n-->\r\n### **Get all rows**\r\nGet all the rows for a given table by using the callback function.\r\n```javascript\r\n\r\nconst db = require('electron-db');\r\nconst electron = require('electron');\r\n\r\nconst app = electron.app || electron.remote.app;\r\n\r\ndb.getAll('customers', (succ, data) => {\r\n  // succ - boolean, tells if the call is successful\r\n  // data - array of objects that represents the rows.\r\n})\r\n```\r\n### **Get Row(s) from the table**\r\nGet row or rows that matched the given condition(s) in WHERE argument\r\n\r\n```javascript\r\nconst db = require('electron-db');\r\nconst electron = require('electron');\r\n\r\nconst app = electron.app || electron.remote.app;\r\n\r\ndb.getRows('customers', {\r\n  address: \"Paco, Botolan, Zambales\",\r\n  name: 'Alexius Academia'\r\n}, (succ, result) => {\r\n  // succ - boolean, tells if the call is successful\r\n  console.log(\"Success: \" + succ);\r\n  console.log(result);\r\n})\r\n\r\n/*\r\n\tOutput:\r\n    \tSuccess: true\r\n        [ { name: 'Alexius Academia',\r\n    address: 'Paco, Botolan, Zambales',\r\n    id: 1508419374272 } ]\r\n*/\r\n```\r\n\r\n### **Update Row**\r\nUpdates a specific row or rows from a table/json file using a WHERE clause.\r\n\r\n```javascript\r\nconst db = require('electron-db');\r\nconst electron = require('electron');\r\n\r\nconst app = electron.app || electron.remote.app;\r\n\r\nlet where = {\r\n  \"name\": \"Alexius Academia\"\r\n};\r\n\r\nlet set = {\r\n  \"address\": \"Paco, Botolan, Zambales\"\r\n}\r\n\r\ndb.updateRow('customers', where, set, (succ, msg) => {\r\n  // succ - boolean, tells if the call is successful\r\n  console.log(\"Success: \" + succ);\r\n  console.log(\"Message: \" + msg);\r\n});\r\n```\r\n\r\n### **Search Records**\r\nSearch a specific record with a given key/field of the table. This method can search part of a string from a value.\r\n\r\nIn this example, I have a table named 'customers', each row has a 'name' property. We are now trying to search for a name in the rows that has the substring 'oh' in it.\r\n\r\n```javascript\r\nconst db = require('electron-db');\r\nconst electron = require('electron');\r\n\r\nconst app = electron.app || electron.remote.app;\r\n\r\nlet term = \"oh\";\r\n\r\ndb.search('customers', 'name', term, (succ, data) => {\r\n  if (succ) {\r\n    console.log(data);\r\n  }\r\n});\r\n\r\n// Output\r\n/*\r\n[ { name: 'John John Academia',\r\n    address: 'Paco, Botolan, Zambales',\r\n    id: 1508419430491 } ]\r\n*/\r\n```\r\n\r\n### **Delete Records**\r\nDelete a specific record with a given key-value pair from the table.\r\n\r\n```javascript\r\n\r\nconst db = require('electron-db');\r\nconst electron = require('electron');\r\n\r\ndb.deleteRow('customers', {'id': 1508419374272}, (succ, msg) => {\r\n  console.log(msg);\r\n});\r\n\r\n```\r\n\r\n### **Get data for specific field**\r\nGet all the field given in a specific key.\r\nThis will return all values on each row that has the key given in the parameter.\r\n```javascript\r\nconst key = 'name'\r\n\r\ndb.getField(dbName, dbLocation, key, (succ, data) => {\r\n    if (succ) {\r\n      console.log(data)\r\n    }\r\n})\r\n```\r\n\r\n### **Clear all Records**\r\nClear all the records in the specified table.\r\n```javascript\r\n// Delete all the data\r\ndb.clearTable(dbName, dbLocation, (succ, msg) => {\r\n    if (succ) {\r\n        console.log(msg)\r\n\r\n        // Show the content now\r\n        db.getAll(dbName, dbLocation, (succ, data) => {\r\n            if (succ) {\r\n                console.log(data);\r\n            }\r\n        });\r\n    }\r\n})\r\n```\r\n\r\n### **Count Records**\r\nCount the number of rows for a given table.\r\n```\r\ndb.count(dbName, dbLocation, (succ, data) => {\r\n    if (succ) {\r\n        console.log(data)\r\n    } else {\r\n        console.log('An error has occured.')\r\n        console.log(data)\r\n    }\r\n})\r\n```\r\n\r\nFor contributions, please see the `CONTRIBUTE.md` file. Thank you.\r\n","readmeFilename":"README.md"}