Code Monkey home page Code Monkey logo

Comments (7)

dfahlander avatar dfahlander commented on June 10, 2024 2

Yes, IndexedDB transactions are ACID and solves exactly this,

Please read the docs! There are plenty of samples: https://dexie.org/docs/API-Reference#transaction

Think of a transaction as a lock where you lock the given tables so that any other piece of code trying to lock the same tables would block before entering it.

from dexie.js.

dfahlander avatar dfahlander commented on June 10, 2024 2

You can read about database transactions in general: https://en.wikipedia.org/wiki/Database_transaction

from dexie.js.

dfahlander avatar dfahlander commented on June 10, 2024 1

Thanks I will read all of these docs! It sounds great, one last question for now is: you mentioned to use a get and put but is it also OK to use a transaction with get and update? Update makes more sense for this I think because I am only updating one of the column values in the table and not the entire row.

You'd need to get and update the object within a transaction. However, make sure not to query the external API within that transaction. Instead query API first, then do the transaction with a get and a put.

Absolutely, update is also ok - it's just that update will internally do get and put because IndexedDB doesn't have update natively, so if you do a get anyway, it's easier to just manipulate the object as you like and then put the result back. Update would imply another get after your get.

from dexie.js.

dfahlander avatar dfahlander commented on June 10, 2024

You'd need to get and update the object within a transaction. However, make sure not to query the external API within that transaction. Instead query API first, then do the transaction with a get and a put.

from dexie.js.

secondl1ght avatar secondl1ght commented on June 10, 2024

Thanks for the response, is there an example of how to properly implement something like this? My specific use-case would be to use Dexie as a local client-side DB for a chat messenger application.

So a there could be messages being sent/received at the same time that need to be added to the DB. When sending a message there will also be multiple status states that will need to be updated on the message record in the DB in real time like failed or success.

So there could be several database read/writes happening all within the same time period if a conversation is happening quickly.

I looked at the Transaction documentation but it wasn't exactly clear to me how that can be used to implement the desired behaviour of not having DB conflicts. Will switching every DB action to a transaction fix this problem even if the actions are happening from many different scopes within the application?

Is this the right page to read to try and understand how Transactions solve this? https://dexie.org/docs/Dexie/Dexie.transaction()

from dexie.js.

secondl1ght avatar secondl1ght commented on June 10, 2024

Thanks I will read all of these docs! It sounds great, one last question for now is: you mentioned to use a get and put but is it also OK to use a transaction with get and update? Update makes more sense for this I think because I am only updating one of the column values in the table and not the entire row.

You'd need to get and update the object within a transaction. However, make sure not to query the external API within that transaction. Instead query API first, then do the transaction with a get and a put.

from dexie.js.

secondl1ght avatar secondl1ght commented on June 10, 2024

Great thanks for the tip, looking forward to implementing these transactions!

from dexie.js.

Related Issues (20)

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.