GithubHelp home page GithubHelp logo

jinjinov / indexeddb.blazor Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 19.0 48 KB

A Blazor library for accessing IndexedDB

License: MIT License

HTML 5.50% C# 94.50%
blazor indexeddb indexeddb-wrapper

indexeddb.blazor's People

Contributors

jinjinov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

indexeddb.blazor's Issues

Could not find 'TimeGhost.IndexedDbManager.openDb'

Library version

1.1.1

OS

Windows 10

Describe the bug

Microsoft.JSInterop.JSException: Could not find 'TimeGhost.IndexedDbManager.openDb' ('TimeGhost' was undefined). error when creating database

Code

@page "/students"
@inject IIndexedDbFactory DbFactory
@implements IDisposable

@code {
    private List<Student> students;
    private IndexedDbContext indexedDbContext;

    protected override async Task OnInitializedAsync()
    {
        indexedDbContext = await this.DbFactory.Create<IndexedDbContext>();
        indexedDbContext.Students.Add(new Student()
        {
            Email = "[email protected]",
            FirstName = "name",
            LastName = "tribe",
            DateOfBirth = DateTime.Now.AddYears(-35)
        });
        await indexedDbContext.SaveChanges();
    }

    public void Dispose()
    {
        indexedDbContext?.Dispose();
    }
}

Exceptions

Microsoft.JSInterop.JSException: Could not find 'TimeGhost.IndexedDbManager.openDb' ('TimeGhost' was undefined).
this happens in line:
indexedDbContext = await this.DbFactory.Create<IndexedDbContext>();

Expected behavior

Database gets created and one student added

Additional context

Using Blazor WASM 5.0 (ASP.NET Core hosted)
Added the service to Client's Program.cs as follows:
builder.Services.AddSingleton<IIndexedDbFactory, IndexedDbFactory>();

SaveChanges doesn't remove items from the inner collection

Library version

1.1.1

OS & OS version

W11x64 + Edge

Describe the bug

Hi,
we were storing state of a form (single entity) in local storage but once we added possibility for attachments we hit the wall with size limits so we moved to indexed DB (no need to elaborate on this).

Originaly it all worked until we found out that opening the DB started to take too long (5-10 seconds) and we are doing it often to keep the data alive. So we reworked our solution to use a single instance of the DB which is created on the application startup instead of creating a new one for each task we perform in the DB.

Then it all stopped working - the in browser DB is good but the one stored in memory keeps track of the removed item(s) with the "Deleted" flag. Sadly when we are trying to get the stored item again we get them all - even the removed ones.

Code example

We have a storage service, which has these two methods with a property DB: IndexedDb with a Set: IndexedSet and two methods for Get and Set of the single instance:

public Object Get() {
  return DB.Set.SingleOrDefault();
}
public void Set(Object? v) {
  DB.Set.Clear(); /* changes state to Deleted */
    if(v != null)
      DB.Set.Add(v); /* adds new item to the inner collection */ 
  DB.SaveChanges(); /* doesn't remove item from the inner collection but correctly updates the browser's Indexed DB */
}

Having the code as follows we end up with exeption 'The input sequence contains more than one element.'

Svc.Get(); // returns null
Svc.Set(new {...}) // populates the collection with one item
Svc.Get(); // returns the item
Svc.Set(new {...}) // replaces correctly in browser but wrong in memory
Svc.Get(); // throws exception because the inner collection contains two elements

Expected behavior

After calling the 'Save changes' method on a DB instance - Deleted record should be removed from the inner collection - when reading them again they shouldn't be there.

Additional context

I went through your code and found out that in the 'SaveChanges' method when resolving the Deleted items they don't get removed from the inner collection

I cannot add more than 50 items

Version
1.1.1

OS
windows visual studio 2019

Describe the bug
Hi I'm doing a site for work and I don't know how to store data offline. I found this great library but sadly I can't add more than 50 items in the same table.
can you help me?

To Reproduce
Steps to reproduce the behavior:
1create a table.
2add more than 50 items
Expected behavior
no need to add at least 10000 items.

MY CODE

            using (var db = await p.Create<ContextDb>())
            {
                Console.WriteLine(db.PersonalDate.Count.ToString());
                await db.SaveChanges();
                int startCount = db.PersonalDate.Count;
                for (int i = startCount + 1; i < startCount + 10; i++)
                {
                    DatiPersonaliStatici.Dati.Email = i.ToString();
                    DatiPersonali po = new DatiPersonali();
                    po.Email = i.ToString();
                    po.NomeMacchina = i.ToString();
                    po.LogIsOk = false;
                    po.AutoLogin = false;
                    po.MieiDati = new ClientDatiUtente();
                    po.MieiDati.Mail= i.ToString();
                    po.MieiDati.Token = i.ToString();
                    po.MieiDati.NumeroDiTelefono = i.ToString();
                    po.MieiDati.Nome = i.ToString();
                    po.MieiDati.Cognome = i.ToString();
                    po.MieiDati.IDAzienda = i;
                    po.MieiDati.NumeroTentativiRestanti = i;
                    db.PersonalDate.Add(po);
                }
                await db.SaveChanges(); 

Additional context
thanks for your patience
Capture

some question

Hi, i not know how to contact you, so i'll write here

there are plan to update at net5.0?

one question, is possible to define multiple keys? how?

Thanks

record duplicate/ update problem

Library version

1.1.1

OS & OS version

win10 blazor webassembly

Describe the bug

record not added/updated correctly when connection is opened only at the start of the program.
if i want update the entity, the orginal entity is added and the modified entity

To Reproduce

add:
if i open connection add record , close connection and do the same with the 2nd record is all ok

but if i open connection at the start of the program and write 1 record, and after another record, i found 3 record,
the entity are not marked as already added

update:
open connection insert 2 record, update the first record, i found 3 records of the first, and 2 records of the second,
the updated record is part of the group of 3 records

Exceptions (if any)

Expected behavior

Additional context

the connection is closed only when application is closed

Doesn't update inner class objects changes on SaveChanges()

Library version

1.1.1

OS & OS version

Windows 10 x64

Describe the bug

I followed as in the README documentation, got the interested entity, changed an inner List to add a new item in it and then did the await db.SaveChanges(); without success.

To Reproduce

using (var db = await DbFactory.Create<indexDb>())
{
	var discussion = db.Discussions.First(d => d.Id == CurrentDiscussionId);
	discussion.Answers.Add(newAnswer);
	await db.SaveChanges();
}

minimally, a Discussion with is Answers look like this:

public class ViewDiscussion
{
  [Key]
  public string Id { get; set; }
  public List<ViewAnswer> Answers { get; set; } = new();
}
public class ViewAnswer
{
  public string Id { get; set; }
  public short Likes { get; set; } = 0;
  public bool IsMaker { get; set; } = false;
  public string Text { get; set; }
  public DateTime? TimeStamp { get; set; }
  
  [JsonIgnore]
  public bool IsEditingPossible => IsMaker && (Comments.Count == 0 || (TimeStamp == null ? false :
	  (DateTime.Now - TimeStamp.Value).TotalMinutes <= VConstants.AnswerExpirationMinutes));
  
  public List<ViewComment> Comments { get; set; } = new();
}
public class ViewComment
{
  public string Id { get; set; }
  public bool IsMaker { get; set; }
  public string Text { get; set; }
}

Exceptions (if any)

None

Expected behavior

The ViewAnswer is added and stored in the IndexedDB

A Method to get all records from a store

Is your feature request related to a problem? Please describe.
I'm trying to retrieve all records in a store with one query.

Describe the solution you'd like
Calling db.Accounts.ToArray(); should give me all the records from the Accounts store.

Describe alternatives you've considered
.Take() with a count of records

Additional context
Looking for a quick way to retrieve all records in a store.

Update browser database schema when new IndexedSet is added

Library version

1.1.1

OS & OS version

Windows 10

Describe the bug

I added a new IndexedSet<> in code but the store was was not added in the browser indexed db schema. Workaround was to delte the entire indexed db and reload the browser.

Set<> implementation

Hi,
Is possible to have the .Set<> function as in entity framework?
I need this becouse i need to use the same query from indexeddb and ms sql server
with the Set<> function i think i can do this

example;
i must do the same from indexeddb & from mssql using entity framework (base class are different, so i can't do like down here)
ctx.pratica.find(10);

something like this (i think) can solve problem
ctx.Set.find(10);

ctx can be dbcontext or IndexedDb (depend what db i must use), for this i need the Set<> (or different solution)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.