{"id":26748358,"url":"https://github.com/nwestfall/blazordb","last_synced_at":"2025-04-14T22:14:42.659Z","repository":{"id":40003903,"uuid":"267983122","full_name":"nwestfall/BlazorDB","owner":"nwestfall","description":"Use IndexedDB in Blazor WebAssembly (WASM)","archived":false,"fork":false,"pushed_at":"2023-02-15T21:29:23.000Z","size":286,"stargazers_count":74,"open_issues_count":10,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-14T22:14:38.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/nwestfall.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}},"created_at":"2020-05-30T00:47:41.000Z","updated_at":"2025-03-14T05:06:06.000Z","dependencies_parsed_at":"2023-02-03T11:45:33.930Z","dependency_job_id":null,"html_url":"https://github.com/nwestfall/BlazorDB","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwestfall%2FBlazorDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwestfall%2FBlazorDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwestfall%2FBlazorDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwestfall%2FBlazorDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nwestfall","download_url":"https://codeload.github.com/nwestfall/BlazorDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968917,"owners_count":21191162,"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":"2025-03-28T10:17:32.891Z","updated_at":"2025-04-14T22:14:42.646Z","avatar_url":"https://github.com/nwestfall.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Forked from [https://github.com/Reshiru/Blazor.IndexedDB.Framework](https://github.com/Reshiru/Blazor.IndexedDB.Framework) as inspiration.  A lot has changed since original fork and a lot is planned to get it closer.\n\n# BlazorDB\n\nAn easy, fast way to use IndexedDB in a Blazor application.\n\n### How to Use (WASM)\n - Install `dotnet add package BlazorIndexedDB`\n - Add `.js` files to `index.html`\n    ```js\n    \u003cscript src=\"_content/BlazorIndexedDB/dexie.min.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"_content/BlazorIndexedDB/blazorDB.js\"\u003e\u003c/script\u003e\n    ```\n - Add `@using BlazorDB` to `_Imports.razor`\n - Update `Program.cs` `ServiceCollection` with new databases (can add as many databases as you want)\n    ```c#\n    builder.Services.AddBlazorDB(options =\u003e\n    {\n        options.Name = \"Test\";\n        options.Version = 1;\n        options.StoreSchemas = new List\u003cStoreSchema\u003e()\n        {\n            new StoreSchema()\n            {\n                Name = \"Person\",\n                PrimaryKey = \"id\",\n                PrimaryKeyAuto = true,\n                UniqueIndexes = new List\u003cstring\u003e { \"name\" }\n            }\n        };\n    });\n    ```\n - Inject `IBlazorDbFactory` in your Razor pages\n    ```c#\n    @inject IBlazorDbFactory _dbFactory\n    ```\n - Start using!\n    ```c#\n    var manager = await _dbFactory.GetDbManager(dbName)\n    await manager.AddRecord(new StoreRecord\u003cobject\u003e()\n    {\n        StoreName = storeName,\n        Record = new { Name = \"MyName\", Age = 20 }\n    });\n    ```\n\n### How it works\nYou defined your databases and store schemes in the `ServicesCollection`.  We add a helper called `AddBlazorDB` where you can build ` DbStore`.  From there, we ensure that an instance of `IBlazorDbFactory` is available in your service provider and will automatically add all `DbStores` and `IndexedDbManagers` based on what is defined with `AddBlazorDb`.  This allows you to have multiple databases if needed.\n\nTo access any database/store, all you need to do is inject the `IBlazorDbFactory` in your page and call `GetDbManager(string dbName)`.  We will pull your `IndexedDbManager` from the factory and make sure it's created and ready.\n\nMost calls will either be true `Async` or let you pass an `Action` in.  If it lets you pass in an `Action`, it is optional.  This `Action` will get called when the method is complete.  This way, it isn't blocking on `WASMs` single thread.  All of these calls return a `Guid` which is the \"transaction\" identifier to IndexeDB (it's not a true database transaction, just the call between C# and javascript that gets tracked).\n\nIf the call is flagged as `Async`, we will wait for the JS callback that it is complete and then return the data.  The library takes care of this connection between javascript and C# for you.\n\n### Available Calls\n - `Task\u003cGuid\u003e OpenDb(Action\u003cBlazorDbEvent\u003e action)` - Open the IndexedDb and make sure it is created, with an optional callback when complete\n - `Task\u003cGuid\u003e DeleteDb(string dbName, Action\u003cBlazorDbEvent\u003e action)` - Delete the database, with an optional callback when complete\n - `Task\u003cBlazorDbEvent\u003e DeleteDbAsync(string dbName)` - Delete the database and wait for it to complete\n - `Task\u003cGuid\u003e AddRecord\u003cT\u003e(StoreRecord\u003cT\u003e recordToAdd, Action\u003cBlazorDbEvent\u003e action)` - Add a record to the store, with an optional callback when complete\n - `Task\u003cBlazorDbEvent\u003e AddRecordAsync\u003cT\u003e(StoreRecord\u003cT\u003e recordToAdd)` - Add a record to the store and wait for it to complete\n - `Task\u003cGuid\u003e BulkAddRecord\u003cT\u003e(string storeName, IEnumerable\u003cT\u003e recordsToBulkAdd, Action\u003cBlazorDbEvent\u003e action)` - Adds records/objects to the specified store in bulk\n - `Task\u003cBlazorDbEvent\u003e BulkAddRecordAsync\u003cT\u003e(string storeName, IEnumerable\u003cT\u003e recordsToBulkAdd)` - Adds records/objects to the specified store in bulk and waits for it to complete\n - `Task\u003cGuid\u003e UpdateRecord\u003cT\u003e(UpdateRecord\u003cT\u003e recordToUpdate, Action\u003cBlazorDbEvent\u003e action)` - Update a record in the store, with an optional callback when c complete\n - `Task\u003cBlazorDbEvent\u003e UpdateRecordAsync(UpdateRecord\u003cT\u003e recordToUpdate)` - Update a record in the store and wait for it to complete\n - `Task\u003cTResult\u003e GetRecordByIdAsync\u003cTInput, TResult\u003e(string storeName, TInput key)` - Get a record by the 'id' and wait for it to return\n - `Task\u003cGuid\u003e DeleteRecord\u003cTInput\u003e(string storeName, TInput key, Action\u003cBlazorDbEvent\u003e action)` - Delete a record in the store by 'id', with an optional callback when complete\n - `Task\u003cBlazorDbEvent\u003e DeleteRecordAsync\u003cTInput\u003e(string storeName, TInput key)` - Delete a record in the store by 'id' and wait for it to complete\n - `Task\u003cBlazorDbEvent\u003e ClearTable\u003cTInput\u003e(string storeName, Action\u003cBlazorDbEvent\u003e action)` - Clears all data from a Table but keeps the table\n - `Task\u003cBlazorDbEvent\u003e ClearTableAsync\u003cTInput\u003e(string storeName)` - Clears all data from a Table but keeps the table and wait for it to complete\n\n### More to Come\n - Real queries\n - Automated testing\n - Dynamically add/remove from `IBlazorDbFactory`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwestfall%2Fblazordb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnwestfall%2Fblazordb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwestfall%2Fblazordb/lists"}