{"id":23324560,"url":"https://github.com/xnodeoncode/i45","last_synced_at":"2025-08-22T18:32:44.840Z","repository":{"id":264081026,"uuid":"881435735","full_name":"xnodeoncode/i45","owner":"xnodeoncode","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-03T17:16:45.000Z","size":3358,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-03T18:25:04.810Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xnodeoncode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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":"2024-10-31T15:10:20.000Z","updated_at":"2024-12-03T17:16:57.000Z","dependencies_parsed_at":"2024-11-22T08:51:00.824Z","dependency_job_id":null,"html_url":"https://github.com/xnodeoncode/i45","commit_stats":null,"previous_names":["xnodeoncode/i45"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnodeoncode%2Fi45","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnodeoncode%2Fi45/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnodeoncode%2Fi45/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnodeoncode%2Fi45/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xnodeoncode","download_url":"https://codeload.github.com/xnodeoncode/i45/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230626764,"owners_count":18255690,"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-20T18:17:46.911Z","updated_at":"2025-08-22T18:32:44.826Z","avatar_url":"https://github.com/xnodeoncode.png","language":"JavaScript","readme":"# i45\n\n[NodeJS package](https://www.npmjs.com/package/i45)\n\nA wrapper for browser storage.\n\n## Installation\n\n```javascript\nnpm i i45\n\n```\n\n## Usage\n\n- [Default Storage Settings](#default-storage-settings)\n- [Custom Storage Settings](#custom-storage-settings)\n- [Multiple Data Contexts](#multiple-data-contexts)\n- [Multiple Data Stores](#using-a-single-datacontext-with-multiple-data-stores)\n- [Retrieving Data](#retrieving-data)\n- [Retrieving Data from Custom Data Stores](#retrieving-data-from-custom-data-stores)\n- [Clearing the Data Store](#clearing-the-data-store)\n- [Storage Locations](#storage-locations)\n- [Using Sample Data](#using-sample-data)\n\n### Default Storage Settings\n\n```javascript\nimport { DataContext } from \"i45\";\n\n// Create an instance of the datacontext.\n// The default storage location is local storage using a default table name.\nvar dataContext = new DataContext();\n\n// Create an array of objects. This is a sample collection of books\nvar book = { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 };\nvar bookTwo = {\n  title: \"Creating NPM Package\",\n  author: \"Oluwatobi Sofela\",\n  id: 123457,\n};\n\nvar books = [];\nbooks.push(book);\nbooks.push(bookTwo);\n\n// Persist the collection to the datastore, passing in array of objects.\ndataContext.store(books);\n```\n\n### Custom Storage Settings\n\n```javascript\nimport { DataContext, DatabaseSettings, StorageLocations } from \"i45\";\n\n// Create a database settings object with the desired values.\n// A primary key field name is required. This example uses \"id\".\nvar settings = new DatabaseSettings(\n  \"BookShelf\",\n  1,\n  \"Books\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// Create an instance of the datacontext, passing in the database settings.\nvar dataContext = new DataContext(settings);\n\n// create an array of objects. This is a sample collection of books\nvar book = { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 };\nvar bookTwo = {\n  title: \"Creating NPM Package\",\n  author: \"Oluwatobi Sofela\",\n  id: 123457,\n};\n\nvar books = [];\nbooks.push(book);\nbooks.push(bookTwo);\n\n// persist the collection to the datastore, passing in the database settings and the collection.\ndataContext.store(books);\n```\n\n### Multiple Data Contexts\n\n```javascript\n/* \nA database settings object with a unique name for each database is required.\n\nSee the examples below.\n*/\n\nimport { DataContext, DatabaseSettings, StorageLocations } from \"i45\";\n\n// These settings can be used to create a data store for storing and retrieving books.\nvar bookshelfSettings = new DatabaseSettings(\n  \"BookShelf\",\n  1,\n  \"Books\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// These settings can be used to create a data store for storing and retrieving cities.\nvar mapSettings = new DatabaseSettings(\n  \"Map\",\n  1,\n  \"Cities\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// Create instances of the datacontext, passing in the relevant database settings. For Cookie storage, tableName is used as the cookie name.\nvar booksContext = new DataContext(bookshelfSettings);\nvar mapContext = new DataContext(mapSettings);\n\n// create an array of objects. This is a sample collection of books\nvar book = { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 };\nvar bookTwo = {\n  title: \"Creating NPM Package\",\n  author: \"Oluwatobi Sofela\",\n  id: 123457,\n};\n\nvar books = [];\nbooks.push(book);\nbooks.push(bookTwo);\n\n// create an array of cities for the mapContext.\nvar c1 = { id: 1, name: \"Seattle\", state: \"Washington\", postalCode: \"98109\" };\nvar c2 = {\n  id: 2,\n  name: \"Bradfordsville\",\n  state: \"Kentucky\",\n  postalCode: \"40009\",\n};\n\nvar cities = [];\ncities.push(c1);\ncities.push(c2);\n\n// persist the objects using the associated context.\nbooksContext.store(books);\nmapContext.store(cities);\n```\n\n### Using a single DataContext with multiple data stores.\n\nTo manage multiple data stores with a single context, you must pass in the associated database settings object with each request.\n\n```javascript\n// Create a data store for storing and retrieving books.\nvar bookshelfSettings = new DatabaseSettings(\n  \"BookShelf\",\n  1,\n  \"Books\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// create an array of books.\nvar book = { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 };\nvar bookTwo = {\n  title: \"Creating NPM Package\",\n  author: \"Oluwatobi Sofela\",\n  id: 123457,\n};\n\nvar books = [];\nbooks.push(book);\nbooks.push(bookTwo);\n\n// Create a data store for storing and retrieving cities.\nvar mapSettings = new DatabaseSettings(\n  \"Map\",\n  1,\n  \"Cities\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// create an array of cities.\nvar c1 = { id: 1, name: \"Seattle\", state: \"Washington\", postalCode: \"98109\" };\nvar c2 = {\n  id: 2,\n  name: \"Bradfordsville\",\n  state: \"Kentucky\",\n  postalCode: \"40009\",\n};\n\nvar cities = [];\ncities.push(c1);\ncities.push(c2);\n\n// Create a data context object\nvar combinedDataStoreContext = new DataContext();\n\n/*\nPersist and retrieve the items using the combined data context passing in the database settings along with the collection.\n*/\n\n// An example uisng the bookshelf settings.\ncombinedDataStoreContext.store(bookshelfSettings, books);\nvar returnedBooks = combinedDataStoreContext.retrieve(bookshelfSettings);\n\n// An example using the map settings.\ncombinedDataStoreContext.store(mapSettings, cities);\nvar returnedCities = combinedDataStoreContext.retrieve(mapSettings);\n```\n\n### Retrieving Data\n\nThe retrieve method on the data context returns a Promise. The example below demonstrates how to retrieve data using default database settings.\n\n```javascript\nimport { DataContext } from \"i45\";\n\nvar context = new DataContext();\n\nvar books = [\n  { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 },\n  { title: \"Creating NPM Package\", author: \"Oluwatobi Sofela\", id: 123457 },\n];\n\ncontext.store(books);\n\ncontext.retrieve().then((data) =\u003e console.log(\"Cookie Data\", data));\n```\n\n### Retrieving Data from Custom Data Stores\n\nTo retrieve data using customized settings, the database settings object must be provided.\n\n```javascript\nimport { DataContext, DatabaseSettings, StorageLocations } from \"i45\";\n\n// Create a database settings object with the desired values.\n// A primary key field name is required. This example uses \"id\".\nvar settings = new DatabaseSettings(\n  \"BookShelf\",\n  1,\n  \"Books\",\n  \"id\",\n  StorageLocations.LocalStorage\n);\n\n// Create an instance of the datacontext, passing in the database settings.\nvar dataContext = new DataContext(settings);\n\n// create an array of objects. This is a sample collection of books\nvar book = { title: \"The Road to React\", author: \"Robin Wieruch\", id: 123456 };\nvar bookTwo = {\n  title: \"Creating NPM Package\",\n  author: \"Oluwatobi Sofela\",\n  id: 123457,\n};\n\nvar books = [];\nbooks.push(book);\nbooks.push(bookTwo);\n\n// persist the collection to the datastore, passing in the database settings and the collection.\ndataContext.store(settings, books);\n\n// retrieve the data.\ndatacontext.retrieve(settings);\n```\n\n### Clearing the Data Store\n\nTo delete an entry, call the clear() method on the data context.\n\n```javascript\nimport { DataContext } from \"i45\";\n\nvar dataContext = new DataContext();\n\n// create an array of cities.\nvar cities = [];\ncities.push({\n  id: 1,\n  name: \"Seattle\",\n  state: \"Washington\",\n  postalCode: \"98109\",\n});\ncities.push({\n  id: 2,\n  name: \"Bradfordsville\",\n  state: \"Kentucky\",\n  postalCode: \"40009\",\n});\n\n// persist the collection\ndataContext.store(cities);\n\n// remove the item from storage.\ndataContext.clear();\n```\n\n### Storage Locations\n\nStorageLocations is an enum of the available storage options which are currently LocalStorage and SessionStorage.\n\n#### Using StorageLocations\n\nWhen creating a DatabaseSettings object and/or creating an instance of a DataContext, one of the storage locations below is required.\n\n```javascript\nStorageLocations.LocalStorage; // uses window.localStorage to persist data.\nStorageLocations.SessionStorage; // uses window.sessionStorage to persist data.\n```\n\n### Using Sample Data\n\nThe i45-Sample-Data package is a library of sample datasets that can be used during development.\n\nThe package has been merged here for convenience.\n\nFull usage details can be found at [i45-Sample-Data](https://www.npmjs.com/package/i45-sample-data)\n\n```javascript\nimport { SampleData } from \"i45\";\n\nvar books = SampleData.JsonData.Books;\n\nconsole.log(books);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnodeoncode%2Fi45","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxnodeoncode%2Fi45","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnodeoncode%2Fi45/lists"}