-
-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model.update does not create 'required' fields, create 'createAt' or create 'updateAt' timestamps. #85
Comments
Sorry for the slow response and thanks for all the detailed info. I'll look into fixing this as soon a can. If someone want's to try to beat me to it, a PR would be welcome. |
I'd love to make a PR for it, but I'm stuck on one thing. Off the top of my head, I can't think of any other way to enforce I'll use my 'apple schema' as an example. When I perform the 'honeygold' update, I only pass the What are your thoughts on this @brandongoode? If you are okay with this approach or have one of your own, let me know and I can make a PR. |
That was the same thing I've been debating. The nice thing about the update is the ability just to send the attributes that are updated. Just sending the updates saves me on some of my projects. I don't want to lose that aspect of the update. What I started thinking about doing was creating an option (schema or system) that would allow you to have an update fail if the key didn't exist. Then you could use a create or save to apply the defaults. This could either be done automatically by dynamoose or manually. What are your thoughts? |
Okay, I've given this some thought and I think our options are:
I feel that the third option is good, however there are some drawbacks. As the default behaviour of dynamoDB is to 'update-or-create', restricting this might feel limiting to some regular dynamoDB users. There is also the matter of actually knowing if we are creating or doing an update. For example, let's say we have the option 'fail-on-update-create' (not a great name, I know) which is set to I suggest doing both option 2 and 3. We carry a few more options that will describe desired behaviour on create and update. These options are then well documented to let users know what they're getting into. |
I agree. A combination of 2 & 3 with the default behavior being the current behavior (at least for now - to prevent breaking existing code). For the 'fail-on-update-create', we may be able to use the ConditionExpression to keep it from creating. This would not require any additional read/write units. It would be the reverse logic of the Option name ideas:
|
I've been working with @aloof-ruf on this, and I would like to propose a 4th option: DynamoDB For The only downside is that from what I see in the documentation, DynamoDB's I will create a PR for this if you agree with this direction going forward. |
Documentation for http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html |
That being said, I've meant to move to using the newer conditional expressions for both Then you could use the |
Thanks for the explanation. I didn't realize that So for now we will just modify the |
Sounds like a good plan. Looking forward to your PR. |
Closed by #96 |
Model.update()
works well when the desired item already exists in the database, but does not do the following when the item does not exist:For example:
apple.js (define schema)
index.js (perform database operations)
Then, the result when I run:
aws dynamodb scan --table-name Apple --endpoint-url http://localhost:8000
is:Notice how the item with id: 4 contains attributes
appleType
andid
but does not contain anything for the 'required' attributestatus
nor does it create the timestamps I specified with{timestamps: true}
.I feel the expected result should be either a rejection/fail when performing an update on an item that does not exist (instead of creating it), or required fields and timestamps should be filled in as they are with
Model.create()
.The text was updated successfully, but these errors were encountered: