tailslide / dnetindexeddb Goto Github PK
View Code? Open in Web Editor NEWThis project forked from amuste/dnetindexeddb
Blazor Library for IndexedDB DOM API
License: MIT License
This project forked from amuste/dnetindexeddb
Blazor Library for IndexedDB DOM API
License: MIT License
Hi,
I am using DnetIndexedDbTs
in latest version 3.5.0
.
In Setup I define two stores like this
builder.Services.AddIndexedDbDatabase<ImageDb>(options =>
{
var indexedDbDatabaseModel = new IndexedDbDatabaseModel
{
Name = "Images",
Version = 1,
Stores = new List<IndexedDbStore>
{
new BlobStore(),
new ImageModelStore()
},
DbModelId = 1,
UseKeyGenerator = false
};
options.UseDatabase(indexedDbDatabaseModel);
});
with class BlobStore
looking like this
public class BlobStore : IndexedDbStore
{
public BlobStore()
{
Name = "BlobStore";
Key = new IndexedDbStoreParameter
{
//KeyPath = "Id"
};
Indexes = new List<IndexedDbIndex>
{
};
}
}
and class ImageModelStore
looking like this
public class ImageModelStore : IndexedDbStore
{
public ImageModelStore()
{
Name = "ImageModelStore";
Key = new IndexedDbStoreParameter
{
KeyPath = "id"
};
Indexes = new List<IndexedDbIndex>
{
new IndexedDbIndex
{
Name = "imageId",
Definition = new IndexedDbIndexParameter
{
Unique = true
}
},
new IndexedDbIndex
{
Name = "originalName",
Definition = new IndexedDbIndexParameter
{
Unique = true
}
},
new IndexedDbIndex
{
Name = "recordKey ",
Definition = new IndexedDbIndexParameter
{
Unique = true
}
},
...
};
}
which maps to class ImageModel
public class ImageModel
{
[IndexDbKey]
public int? Id { get; set; }
[IndexDbIndex]
public Guid ImageId { get; set; } = Guid.Empty;
[IndexDbIndex]
public string OriginalName { get; set; } = string.Empty;
[IndexDbIndex]
public string RecordKey { get; set; } = string.Empty;
...
}
Now I am adding new items like this
public async Task StoreInfo(ImageModel imageModel, byte[] content)
{
await _imageDb.OpenIndexedDb();
var imageInfoStore = "ImageModelStore";
var dtoResult = await _imageDb.AddItems(imageInfoStore, [imageModel]); // [imageModel] is short for new List<ImageModel >{ imageModel }
var blobStore = "BlobStore";
var result = _imageDb.AddBlobItem(blobStore, content, "application/octet-stream", imageModel.RecordKey);
}
I am calling StoreInfo
for testing like this
public async Task TestIndexedDb()
{
var array = Encoding.UTF8.GetBytes("rather long test string");
var info = new ImageModel
{
ImageId = Guid.NewGuid(),
OriginalName = "best name.jpg",
RecordKey = Guid.NewGuid().ToString().Replace("-", ""),
Id = RandomNumberGenerator.GetInt32(100)
};
await StoreInfo(info, array);
StateHasChanged();
}
The first time I call TestIndexedDb
to add items everything works fine.
However if I call TestIndexedDb
more than once I do get issues with line await _imageDb.AddItems(imageInfoStore, [imageModel]);
. If I comment out I can add multiple blobs for _imageDb.AddBlobItem(blobStore, content, "application/octet-stream", imageModel.RecordKey);
.
How can I add multiple entries for ImageModelStore
one item a time?
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.