Giter VIP home page Giter VIP logo

Comments (13)

tywalch avatar tywalch commented on July 19, 2024 4

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.

tywalch avatar tywalch commented on July 19, 2024 1

@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.

tywalch avatar tywalch commented on July 19, 2024 1

I also would love to hear @sam3d weigh in on this too btw

from electrodb.

tywalch avatar tywalch commented on July 19, 2024 1

@misterjoshua

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.

tywalch avatar tywalch commented on July 19, 2024 1

Just merged, here's a playground showing its use, let me know if you experience any issues!

from electrodb.

misterjoshua avatar misterjoshua commented on July 19, 2024

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.

tywalch avatar tywalch commented on July 19, 2024

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.

misterjoshua avatar misterjoshua commented on July 19, 2024

@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.

tywalch avatar tywalch commented on July 19, 2024

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.

misterjoshua avatar misterjoshua commented on July 19, 2024

@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.

misterjoshua avatar misterjoshua commented on July 19, 2024

I took a peek at aec1f57 and had a comment about the condition expression. My comment is inline here: aec1f57#r125880163

from electrodb.

misterjoshua avatar misterjoshua commented on July 19, 2024

@misterjoshua

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.

misterjoshua avatar misterjoshua commented on July 19, 2024

Thank you for all the work you've put into this so far!

from electrodb.

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.