Comments (7)
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.
You can read about database transactions in general: https://en.wikipedia.org/wiki/Database_transaction
from dexie.js.
Thanks I will read all of these docs! It sounds great, one last question for now is: you mentioned to use a
get
andput
but is it also OK to use a transaction withget
andupdate
? 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.
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.
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.
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.
Great thanks for the tip, looking forward to implementing these transactions!
from dexie.js.
Related Issues (20)
- Dexie Cloud Feature request: user-specific public realm
- Is it possible to invite a user who is not signed up? HOT 6
- Error: too much recursion HOT 1
- Typescript returns errors regarding ID that is undefined HOT 11
- bulkDelete() for large number of primary keys is way too slow
- WebPush for DexieCloud Feature Request
- Dexie Cloud feature request: in-app invitations HOT 1
- dexie cloud db entries with image blob disapear HOT 2
- Return only one field?
- Typescript complain with compound ID HOT 2
- related tables in dexie HOT 2
- Dexie Cloud Manager - "Manage users" error HOT 3
- Authentication error with the fresh.deno framework HOT 1
- Issue with Dexie's table.where() Method when Targeting Existing IndexedDB with Indexed KeyPath
- "default" is not exported by "../../../Dexie.js/dist/dexie.min.js", imported by "../../../Dexie.js/import-wrapper-prod.mjs". HOT 14
- Transaction context is lost when running a recursive call in a loop HOT 8
- Backwards compatibility issue - ReferenceError: queueMicrotask is not defined HOT 2
- circularly reference on update HOT 10
- dexie-cloud feature request: Transaction support on REST API HOT 3
- Incomaptibility between Dexie.js v4.0.7 and @opentelemetry/context-zone 1.18.1 even with forcing last version of zone.js version 0.14.6 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dexie.js.