Coder Social home page Coder Social logo

dnetindexeddb's People

Contributors

amuste avatar bgriffy avatar dharmaturtle avatar mcbride-clint avatar rebelweb avatar tailslide avatar

Stargazers

 avatar  avatar

Watchers

 avatar

dnetindexeddb's Issues

Cannot add more than one item

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?

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.