Comments (13)
I have opened this PR (nearly ready to merge) that adds support for add
, subtract
, and append
operations on upsert
: #296 🎉
I will merge soon, likely tomorrow
from electrodb.
@misterjoshua Thanks! This hasn't been published yet, the fact this commit made it to master was a mistake in a local script 👎. When this is ready to be published there will be additional tests and I will ensure this missing paren gets added.
from electrodb.
I also would love to hear @sam3d weigh in on this too btw
from electrodb.
Small update: I am rethinking this approach because it unfortunately conflicts with some of the goals associated with .composite()
. I think the solution here must be adding the mutation methods to upsert.
from electrodb.
Just merged, here's a playground showing its use, let me know if you experience any issues!
from electrodb.
I updated to ElectroDB 2.9.1 and I tried the .composite()
method on an update, thinking maybe that would include the secondary index keys. But unfortunately, it appears the condition expression constraint prevents the item from being created.
Here's a playground to show what I mean: Playground
from electrodb.
Hi @misterjoshua 👋
It sounds like you're intentionally using "update" to create an item. To better understand your need, can you checkout the "upsert" method (https://electrodb.dev/en/mutations/upsert/) and let me know if that is capable of doing what you need?
The "composite" function on update is for cases where a composite attribute can't be set, e.g. because the property is readOnly.
from electrodb.
@tywalch Hi. Thanks for responding.
Yes, I am intentionally using update
to create the item if it doesn't exist - but if it does exist, then the write operation should add a numeric value to a numeric item attribute. The DynamoDB ADD keyword lets you do this blindly and you can combine with SET
to write a complete record if you know the rest of the item attributes at the time of write, which I do.
No, unfortunately, the upsert
method can't do what I'm after, as it requires I know what value the attribute should be after the ADD
operation, but I don't because I'm trying to avoid the unnecessary overhead of reading the record I'm updating, as reading the item increases both the cost and latency of the operation.
from electrodb.
Gotcha, this makes sense. In the short term, I'm thinking it might be worth updating the composite
condition to be something like (${name} = ${value} or attribute_not_exists(${name})
. In the long term, I am hoping to add support for methods like add
to be used with upsert
since you're not the first to ask for this. Would this address your need?
from electrodb.
@tywalch Yes, conditions looking like (${name} = ${value} or attribute_not_exists(${name})
would work nicely in the interim, and I like your longer-term idea as well. Thank you.
from electrodb.
I took a peek at aec1f57 and had a comment about the condition expression. My comment is inline here: aec1f57#r125880163
from electrodb.
Small update: I am rethinking this approach because it unfortunately conflicts with some of the goals associated with
.composite()
. I think the solution here must be adding the mutation methods to upsert.
Sounds good to me. The mutation methods on upsert could work well for my use case.
How do you think this would look, btw? Something like this?
entity.upsert(allAttributesExceptThoseInTheAdd)
.add({ attribute: 1 })
.go();
from electrodb.
Thank you for all the work you've put into this so far!
from electrodb.
Related Issues (20)
- How does it work with Python? HOT 2
- Filter expressions: Where In operation
- Malformed cursor causing issues with paginated queries HOT 3
- Index condition does only identify impacted pk on upsert and not on patch or update HOT 18
- key should be case sensitive HOT 1
- Support `ConsistentRead` option HOT 2
- Update nested Map value using set() method. HOT 2
- Incorrect key generated when using composite operation on patch/update HOT 3
- Doc example incorrect and misleading HOT 3
- Examples for adjacency lists and Materialized graphs
- Empty Collection to work with "Service" construct
- Simplest implementation of unique constraint for non-key attributes
- Support for BigInt HOT 9
- Feature Request? Query by > 1 partition key values. HOT 2
- Created items not returned when using a transaction HOT 2
- Handling unstructured maps HOT 5
- ReturnValuesOnConditionCheckFailure is not available for non-transactional operations HOT 5
- Collection validation should check `field` property of composite attributes
- Setter not triggered on removing a watching attribute HOT 1
- feature: support async getters/setters HOT 1
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 electrodb.