{"id":31051809,"url":"https://github.com/ajay-develops/indexeddb","last_synced_at":"2026-03-01T23:03:37.566Z","repository":{"id":117636619,"uuid":"525506182","full_name":"ajay-develops/indexedDB","owner":"ajay-develops","description":"source - yt Heussein Nasser","archived":false,"fork":false,"pushed_at":"2022-08-19T06:30:44.000Z","size":1398,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-15T14:30:39.064Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/ajay-develops.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-16T18:53:39.000Z","updated_at":"2022-08-17T04:09:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"f129e1fe-643d-439a-ac19-7c10d7c2cd6b","html_url":"https://github.com/ajay-develops/indexedDB","commit_stats":null,"previous_names":["templar-ajay/indexeddb","ajay-develops/indexeddb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajay-develops/indexedDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2FindexedDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2FindexedDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2FindexedDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2FindexedDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajay-develops","download_url":"https://codeload.github.com/ajay-develops/indexedDB/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2FindexedDB/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29987656,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T22:42:38.399Z","status":"ssl_error","status_checked_at":"2026-03-01T22:41:51.863Z","response_time":124,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-09-15T00:55:06.177Z","updated_at":"2026-03-01T23:03:32.557Z","avatar_url":"https://github.com/ajay-develops.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IndexedDB\n\n### Flow of indexedDB\n\n![flowchart of working of indexedDB](./flowchart.png)\n\nSpecify database schema , open a connection with your database and then retrieve and update data within a series of transactions.\n\n## Open a database\n\n`const request = indexedDB.open(dbName,dbVersion)`\n\n## events\n\n    - onupgradeneeded\n    - onerror\n    - onsuccess\n\n```js\nrequest.onupgradeneeded = (e) =\u003e {}; // on each version create you have to create dataStores again and enter the data again in them\nrequest.error = (e) =\u003e {};\nrequest.success = (e) =\u003e console.log(`error ! ${e.target.error}`);\n```\n\n## Access the Database\n\n- access database in `onupgradeneeded` event or the `success` event using\n  `event.target.result`\n\nex-\n\n```js\nrequest.success = (event) =\u003e console.log(\"db\", event.target.result);\n//or\nrequest.onupgradeneeded = (e) =\u003e console.log(\"db\", e.target.result);\n//or\nrequest.success = (event) =\u003e console.log(\"db\", request.result); // here event is success , target is request)\n```\n\n## add to the database\n\n1. ### Create a Transaction\n\n- create a transaction for the desired objectStoreName with the permissions required `\"readwrite\"` or `\"readonly\"`. By default the permission is set to `\"readonly\"` , so you can skip the second argument (of permissions) if you require only read access\n\n#### Syntax to create a transaction\n\n```js\nconst tx = db.transaction(\"\u003cname-of-objectStore\u003e\", \"\u003cpermissions-required\u003e\");\n\n// below are a few examples of creating a transaction\n\nconst tx = db.transaction(\"personal_notes\", \"readwrite\");\n\n// or if I only require read access I can write\nconst tx = db.transaction(\"personal_notes\", \"readonly\");\n// or\nconst tx = db.transaction(\"personal_notes\"); // you can skip readonly cuz by default all transactions are readonly\n```\n\n### catch errors in transaction\n\n- `.onerror` event is used to catch errors while a transaction is processing\n\n#### syntax to write a onerror\n\n```js\ntx.onerror = (e) =\u003e {\n  alert(`Error occurred -\u003e ${e.target.error}`);\n  // can also use `tx.error` in place of `e.target.error` since they mean the same thing\n};\n```\n\n2. ### Get the ObjectStore and add data into it\n\n####syntax to get the objectStore from the transaction and add data in it\nexample-\n\n```js\n// define data or fetch it , here we will define it\n data = {\n    title:`note1 ${Math.random()}`,\n    text:`this our Note friend`\n }\n\n// access the objectStore from the transaction\nconst pNotes = tx.objectStore(\"personal_notes);\n// add data to the objectStore\npNotes.add(data)\n```\n\n## View Database\n\n1. Create a transaction with the desired objectStore and readonly access\n2. get the object store from the transaction\n3. make the .openCursor() request.\n4. define the onsuccess event of the request to - if the cursor has any value then display it and then move on to the next cursor with -\u003e cursor.continue() , and if there is no value in cursor then do nothing\n5. access the cursor values object with - `cursor.value`\n\nfollowing is an example to view database\n\n```js\nfunction viewNotes() {\n  const tx = db.transaction(\"personal_notes\"); // this by default gives the transaction readonly access\n  const pNotes = tx.objectStore(\"personal_notes\");\n\n  request = pNotes.openCursor(); //makes a request to open cursor\n\n  request.onsuccess = (e) =\u003e {\n    const cursor = e.target.result // cursor is the result of the request made to openCursor from objectStore - pNotes\n\n    if(cursor){\n      alert(note primaryKey: ${cursor.primaryKey} , title: ${cursor.value.title}, text: ${cursor.value.text})\n\n      cursor.continue() // recalls the openCursor() request to provide the next cursor or the next object of the specified objectStore\n\n    } // if the cursor is empty it does nothing and stops the loop\n  };\n}\n```\n\n# Full Methods\n\n#### source MDN\n\n## 1. Connecting to a database\n\n1. IDBFactory\n\n   - IDBFactory.open()\n   - IDBFactory.deleteDatabase()\n   - IDBFactory.cmp() _compares two keys and returns result indicting the greater one_ - _used in Web Workers_\n\n## 2. Retrieving and Modifying Data\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-develops%2Findexeddb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajay-develops%2Findexeddb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-develops%2Findexeddb/lists"}