Giter Site home page Giter Site logo

Create if not exists about dynogels HOT 3 CLOSED

clarkie avatar clarkie commented on May 18, 2024 1
Create if not exists

from dynogels.

Comments (3)

clarkie avatar clarkie commented on May 18, 2024

@rafoli I've been doing some digging into this and following your discussion with @set-killer on ryanfitz/vogels#189 I think I have an answer for you.

The conditions are checked but only when the id matches an existing id. For dynamo to check for the existence of a value in a property other than a hashkey then it would need to scan the table. This is not what dynamodb is designed for.

I've just added the following example to the repo: https://github.com/clarkie/dynogels/blob/master/examples/conditionalWrites.js

from dynogels.

clarkie avatar clarkie commented on May 18, 2024

I think the documentation / api for dynogels is slightly misleading. In the dynamodb docs it states

To write an item, you use operations such as PutItem, UpdateItem and DeleteItem. Using conditional expressions with these operations, you can control how and under what conditions an item can be modified. You can prevent an update from occurring if the item does not meet some condition beforehand. For example, you can prevent PutItem from overwriting an existing item.

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html

The Model.create method sends a PutItem request which could be slightly misleading.

from dynogels.

rafoli avatar rafoli commented on May 18, 2024

Thanks @clarkie for your detailed answer.

I've changed my code to use a hashKey based on some fields, in that way, avoiding scan the table.

query.queryId = crypto.createHash('md5')
       .update(JSON.stringify({ email: query.email, name: query.name }))
       .digest("hex");   

So now, This { overwrite: false } suits my needs.

...create(query, { overwrite: false }, function(err, res) {

from dynogels.

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.