DrUalcman-BlazorIndexedDb 1.3.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package DrUalcman-BlazorIndexedDb --version 1.3.11                
NuGet\Install-Package DrUalcman-BlazorIndexedDb -Version 1.3.11                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DrUalcman-BlazorIndexedDb" Version="1.3.11" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DrUalcman-BlazorIndexedDb --version 1.3.11                
#r "nuget: DrUalcman-BlazorIndexedDb, 1.3.11"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DrUalcman-BlazorIndexedDb as a Cake Addin
#addin nuget:?package=DrUalcman-BlazorIndexedDb&version=1.3.11

// Install DrUalcman-BlazorIndexedDb as a Cake Tool
#tool nuget:?package=DrUalcman-BlazorIndexedDb&version=1.3.11                

Simple way to interact with IndexedDB and manage the data using List<> and LinkQ

NuGet installation

PM> Install-Package DrUalcman-BlazorIndexedDb

Current features

Connect and create database Define PrimaKey in the model Add record Remove record Edit record

How to use

In the index.html add this references

    <script src="_content/DrUalcman-BlazorIndexedDb/jsDB.js"></script>
    <script src="_content/DrUalcman-BlazorIndexedDb/MyDbJs.js"></script>

BlazorIndexedDb requires an instance IJSRuntime, should normally already be registered.

Create any code first database model you'd like to create and inherit from IndexedDb. You must be use the attribute IndexDb to setup the properties.

Your model (eg. PlayList) should contain an Id property or a property marked with the key attribute.

    public class PlayList
    {
        [IndexDb(IsKeyPath = true, IsAutoIncemental = false, IsUnique = true)]
        public string Id { get; set; }
        public string Url { get; set; }
        public string Title { get; set; }
        public string Ownner { get; set; }
    }

You need import namespace

using Microsoft.JSInterop;
using BlazorIndexedDb;
using BlazorIndexedDb.Models;

Then can create a DBContext class to manage the database like in EF using a constructor with IJSRuntime and properties with the server about how to manage your tables.

public class DBContext
    {
        #region properties
        public PlayListService PlayList { get; private set; }
        #endregion

        #region constructor
        public DBContext(IJSRuntime js)
        {
            _ = js.DbInit("BlazorYoutubePlayer", 1, 			//db name and version
                new string[] { "PlayList" }, 				//table to use, each table must be match with the model class
                "BlazorYoutubePlayerViewer", 				//assembly name
                "BlazorYoutubePlayerViewer.DataBase.Entities");		//namespace where is defined the models classes
            PlayList = new PlayListService(js);
        }
        #endregion

        #region helpers
        public void ProcessErrors(List<ResponseJsDb> result)
        {
            string errors = string.Empty;
            foreach (ResponseJsDb error in result)
            {
                errors += error.Message + "<br/>";
            }
            Console.WriteLine(errors);
        }
        #endregion
    }

The service class example

public class PlayListService
    {
        private readonly IJSRuntime DBConn;
        public PlayListService(IJSRuntime js)
        {
            DBConn = js;
        }

        public async Task<List<PlayList>> GetAsync() =>
            await DBConn.DbSelect<PlayList>();

        public async Task<PlayList> GetAsync(string id) =>
            await DBConn.DbSelect<PlayList>(id);

        public async Task<ResponseJsDb> AddAsync(PlayList toAdd)
            => await DBConn.DbInsert(toAdd);

        public async Task<ResponseJsDb> UpdateAsync(PlayList toAdd)
            => await DBConn.DbUpdate(toAdd);

        public async Task<ResponseJsDb> DeleteAsync(string id)
            => await DBConn.DbDelete<PlayList>(id);
    }

In the index.razor component, or the first component need to use a IndexDb, use this code to create or open the database with all your model classes.

        [Inject]
        public IJSRuntime JsRuntime { get; set; }
        public DBContext _DBContext;
        protected override void OnInitialized()
        {
            _DBContext = new DBContext(JsRuntime);
        }

You can modify the model classes any time, but if the model you will pass don't match with the model created when create the IndexDb this will return a exception.

IJSRuntime Db extensions

  1. DbSelect<TModel>
  2. DbInsert<TModel>
  3. DbUpdate<TModel>
  4. DbDelete<TModel>

Working with records

In all the select action you will receive the List<TModel> except if you are looking for one Key Id send, then you will receive the Model object. In all actions you will receive a ResponseJsDb model or a List<ResponseJsDb> with all the responses, if you are sending a lot of rows.\

    public class ResponseJsDb
    {
        public bool Result { get; set; }
        public string Message { get; set; }
    }

More info

Check our web to (under construction) to get more info.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.47 105 10/10/2024
1.7.46 178 9/5/2024
1.6.45 107 9/4/2024
1.6.44 110 8/30/2024
1.6.43 136 8/17/2024
1.6.42 92 8/7/2024
1.6.41 263 6/22/2024
1.6.40 278 4/16/2024
1.6.39 215 3/26/2024
1.6.38 237 2/28/2024
1.6.37 178 2/27/2024
1.6.36 221 2/27/2024 1.6.36 is deprecated because it has critical bugs.
1.6.35 236 2/18/2024
1.6.34 645 10/10/2023
1.6.33 386 8/18/2023
1.6.32 784 3/23/2023
1.6.31 808 1/28/2023
1.6.30 888 8/10/2022
1.6.28 844 5/25/2022
1.6.27 854 4/3/2022
1.6.26 797 4/3/2022
1.6.25 768 4/3/2022
1.5.24 620 12/28/2021
1.5.23 554 12/27/2021
1.5.22 597 12/19/2021
1.5.21 664 11/15/2021
1.5.20 736 11/14/2021
1.5.19 773 10/25/2021
1.5.18 679 10/24/2021
1.5.17 720 8/29/2021
1.4.16 670 8/9/2021
1.4.15 692 8/8/2021
1.4.14 656 8/3/2021
1.4.13 794 7/12/2021
1.3.11 742 5/8/2021
1.3.10 695 5/2/2021

Fix wrong spellings
Add new add and insert ofline for single register
Add config static class
Fix add register with a column from a table reference
Add console.warning in javascript for dev know the error when have a exception