Giter Club home page Giter Club logo

Comments (6)

mobsense avatar mobsense commented on July 21, 2024

You can only do simple put / delete operation in a batch on the primary key.

The OneTable remove ... many: true does a query under the hood to identify the items to remove. So that cannot be done in a batch.

You can do the query yourself, then put each simple remove into the batch. Of course, there is a limit of 25 ops per batch.

It would be great if DDB could provide a higher performance way to delete items. ;-)

from dynamodb-onetable.

demsey2 avatar demsey2 commented on July 21, 2024

The OneTable remove ... many: true does a query under the hood to identify the items to remove. So that cannot be done in a batch.

  1. what is the reason you query first and then delete?

You can do the query yourself, then put each simple remove into the batch. Of course, there is a limit of 25 ops per batch.

  1. do you mean build a batch with commands based on Expression and then call Table.batchWrite ?

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

You don't need to. You can just delete using the primary key.

But say you want to delete many items based on a query? i.e. a filter expression. OneTable supports doing a remove() with a filter expression via params.where. This does a query first, then removes the matching items. The many:true is a safety to make sure you really want to do this.

Regarding (2). Not necessarily.

Basically, if you know the primary key, just do a remove with batch. Job done.

If you don't know the primary key, then you need to do a query first to determine those keys. Then you can batch delete.

from dynamodb-onetable.

demsey2 avatar demsey2 commented on July 21, 2024

Basically, if you know the primary key, just do a remove with batch. Job done.

this is what I am trying to do with the code above, I call logByEventType.remove()
my keys for that model are:

pk: { type: String, value: '${slug}#log-event-type#${type}' },
sk: { type: String, value: 'log#${logId}#${id}' },

but I need to delete specific records based on pk and sk

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

So you do:

await this.logByEventType.remove({slug, logId, id}, {batch})

then run the batch. The type is supplied by OneTable.

i.e. you provide all the components of the PK/SK.

from dynamodb-onetable.

demsey2 avatar demsey2 commented on July 21, 2024

ok I just realized my problem, my sort key has an additional {id} component and I was expecting to delete where sk: begins_with but that is only supported for query

thanks for your help

from dynamodb-onetable.

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.