jinjinov / indexeddb.blazor Goto Github PK
View Code? Open in Web Editor NEWA Blazor library for accessing IndexedDB
License: MIT License
A Blazor library for accessing IndexedDB
License: MIT License
1.1.1
Windows 10
Microsoft.JSInterop.JSException: Could not find 'TimeGhost.IndexedDbManager.openDb' ('TimeGhost' was undefined).
error when creating database
@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();
}
}
Microsoft.JSInterop.JSException: Could not find 'TimeGhost.IndexedDbManager.openDb' ('TimeGhost' was undefined).
this happens in line:
indexedDbContext = await this.DbFactory.Create<IndexedDbContext>();
Database gets created and one student added
Using Blazor WASM 5.0 (ASP.NET Core hosted)
Added the service to Client's Program.cs as follows:
builder.Services.AddSingleton<IIndexedDbFactory, IndexedDbFactory>();
1.1.1
W11x64 + Edge
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.
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
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.
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
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();
Closed because you didn't provide C# code to reproduce the problem.
Originally posted by @Jinjinov in #5 (comment)
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
1.1.1
win10 blazor webassembly
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
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
the connection is closed only when application is closed
1.1.1
Windows 10 x64
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.
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; }
}
None
The ViewAnswer
is added and stored in the IndexedDB
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.
1.1.1
Windows 10
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.
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.