{"id":18060833,"url":"https://github.com/0xleif/datastore","last_synced_at":"2026-05-19T10:04:56.215Z","repository":{"id":183100848,"uuid":"669584436","full_name":"0xLeif/DataStore","owner":"0xLeif","description":"An extendable data storage solution with built-in caching capabilities.","archived":false,"fork":false,"pushed_at":"2023-11-12T01:13:50.000Z","size":26,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T12:29:54.921Z","etag":null,"topics":["cache","datastore","ios","loading","macos","observableobject","service","storing","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":"https://datastore.0xl.io/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xLeif.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-22T18:50:52.000Z","updated_at":"2023-08-17T18:18:07.000Z","dependencies_parsed_at":"2024-10-31T04:10:46.601Z","dependency_job_id":"de27cb7a-98bf-41af-b98a-cea10e551d53","html_url":"https://github.com/0xLeif/DataStore","commit_stats":null,"previous_names":["0xleif/datastore"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/0xLeif/DataStore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xLeif%2FDataStore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xLeif%2FDataStore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xLeif%2FDataStore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xLeif%2FDataStore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xLeif","download_url":"https://codeload.github.com/0xLeif/DataStore/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xLeif%2FDataStore/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269579633,"owners_count":24441372,"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","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cache","datastore","ios","loading","macos","observableobject","service","storing","swift","tvos","watchos"],"created_at":"2024-10-31T04:10:40.489Z","updated_at":"2026-05-19T10:04:56.187Z","avatar_url":"https://github.com/0xLeif.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataStore\n\n*An extendable data storage solution with built-in caching capabilities.*\n\n## What is DataStore?\n\n`DataStore` is a generic data storage and caching library for Swift. It provides a convenient way to load, cache, and store data in your apps. The `DataStore` class, by default, utilizes a cache to improve data loading performance. However, it can be subclassed to support other data storage mechanisms while still benefiting from the caching capabilities.\n\n## Features\n\n- **Data Loading**: Easily load data from various sources, such as network requests or local databases, by providing a custom `DataLoading` object.\n- **Caching**: By default, `DataStore` integrates a caching mechanism to enhance data loading performance. `DataStore` uses [`Cache`](https://github.com/0xLeif/Cache) as its caching solution.\n- **Flexible Data Retrieval**: Access loaded data via the `fetch()` method or fetch data based on specific criteria using closure-based filtering.\n- **Data Storage**: Store new data objects into the `DataStore` for later retrieval.\n- **Data Deletion**: Remove previously stored data objects from the `DataStore`.\n\n## Installation\n\n### Swift Package Manager (SPM)\n\nAdd the following line to your Package.swift file in the dependencies array:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/0xLeif/DataStore.git\", from: \"0.1.0\")\n]\n```\n\n## Usage\n\n### Creating a DataStore\n\nTo create a `DataStore`, you need to provide a `DataLoading` object. The `DataLoading` object encapsulates the logic to load data from a specific source, such as a network request or local database. You can easily subclass `DataStore` to implement your own data storage mechanism, while still utilizing the caching capabilities.\n\n```swift\nlet store = DataStore(loader: YourDataLoader())\n```\n\n### Loading Data\n\nYou can load data into the `DataStore` using the `load()` method. This will asynchronously load the data using the provided data loader.\n\n```swift\ntry await store.load()\n```\n\nYou can also load data with a specific identifier using the `load(id:)` method:\n\n```swift\nlet expectedID = \"some-id\"\ntry await store.load(id: expectedID)\n```\n\n### Fetching Data\n\nYou can fetch the loaded data from the `DataStore` using the `fetch()` method. This will return an array of the loaded data objects.\n\n```swift\nlet values = store.fetch()\n```\n\nYou can also fetch data with a specific identifier using the `fetch(id:)` method:\n\n```swift\nlet expectedID = \"some-id\"\nlet value = try store.fetch(id: expectedID)\n```\n\nAdditionally, you can fetch data that matches specific conditions using the `fetch(where:)` method with a closure:\n\n```swift\nlet values = store.fetch { data in\n    // Condition to filter the data, e.g. data.color == .red\n}\n```\n\n### Storing Data\n\nYou can store new data in the `DataStore` using the `store(data:)` method. This will add the provided data objects to the store.\n\n```swift\ntry store.store(\n    data: [\n        YourDataObject(\n            // Provide values for your data object properties\n        )\n    ]\n)\n```\n\n### Deleting Data\n\nYou can delete previously stored data from the `DataStore` using the `delete(data:)` method. This will remove the data objects with the specified identifiers from the store.\n\n## Example\n\nHere are some usage examples to demonstrate how to use the `DataStore` library:\n\n```swift\n// Example 1: Loading and fetching data\nlet store = DataStore(loader: YourDataLoader())\ntry await store.load()\nlet values = store.fetch()\n\n// Example 2: Storing and fetching data\nlet expectedID = \"some-id\"\ntry store.store(\n    data: [\n        YourDataObject(\n            id: expectedID,\n            // Provide values for your data object properties\n        )\n    ]\n)\nlet value = try store.fetch(id: expectedID)\n\n// Example 3: Deleting data\ntry store.delete(data: [value.id])\n```\n\n## Contributing\n\nContributions are welcome! If you encounter any issues, have feature requests, or want to contribute code improvements, please feel free to open an issue or submit a pull request.\n\n## License\n\nDataStore is released under the MIT License. See `LICENSE` for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xleif%2Fdatastore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xleif%2Fdatastore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xleif%2Fdatastore/lists"}