I am using watchQuery to get data from the backend and subscribe to the observable. I need to change the data returned from the backend, but they are all read-only property. How can I modify the data?
If you have a subscription on an observable you might want to use the updateQuery functionality. Example in the docu.
There you see that you can update the store using the subscribeToMore functionality of your query. Therein you add the updateQuery function which gives you the result of the subscription. Now you can copy the result of the subscription update it accordingly and return the updated query.
Related
I am using AWS proxy with AWS API Gateway to interact with a DynamoDB table. I have an API resource, under which I have a GET method with the below configuration:
The API uses the Scan action as seen above to fetch all the items from the DynamoDB table. I also have the following request integration mapping template;
{
"TableName": tableName
}
Its really simple. But my problem is that I would like to add another GET method to get each item by their id, which will be supplied in the URL as a param. However, since I have already setup one GET method, I am not able to setup another to fetch only a single item. I am aware I can use mapping templates and Scan as given in the docs to conditionally fetch items if a param is given, but that would mean scanning the entire table, which is a waste each time I want to fetch a single item.
Is there any other way to do this?
We use DynamoDB UpdateItem.
This acts as an "upsert" as we can learn from the documentation
Edits an existing item's attributes, or adds a new item to the table if it does not already exist. [...]
When we make a request, to determine if an item was created or an existing item was updated, we request ALL_OLD. This works great and allows us to differentiate between update and create.
As an additional requirement we also want to return ALL_NEW, but still know the type of operation that was performed.
Question: Is this possible to do in a single request or do we have to make a second (get) request?
By default this is not supported in DynamoDB, there is no ALL or NEW_AND_OLD_IMAGES as there is in DynamoDB streams, but you can always go DIY.
When you do the UpdateItem call, you have the UpdateExpression, which is basically the list of changes to apply to the item. Given that you told DynamoDB to return the item as it looked like before that operation, you can construct the new state locally.
Just create a copy of the ALL_OLD response and locally apply the changes from the UpdateExpression to it. That's definitely faster than two API calls at the cost of a slightly more complex implementation.
I am trying to load my data using a separate query to the server after the records get dirty in the store. The updated values are sent to the server and relevant actions are performed using a custom ajax call and handled at the server side to update all the related records. But when the data is loaded again I get the above mentioned error.
The possible reason could be, since the records are dirty in the store, and without committing the store I am trying to load the data again, it is giving me the error. So, I tried to do an "Application.defaultTransaction.rollback()". It removes those records from the updated bucket, but the "key" in the updated bucket (the object type) still exists and I still get the error. Can anyone help me with this?
In short: is there a way to force clean the store or move all the objects in created/updated/inflight buckets to clean bucket?
Application.store.get('defaultTransaction').rollback() will remove any dirty objects in the store and take it to the initial state.
There is an open issue for store.rollback() too which might be an alternative when merged to master.
https://github.com/emberjs/data/pull/350#issuecomment-9578563
I took a look through the documentation, but couldn't find it. Can anybody who has used the service answer this?
DynamoDB objects' attributes can be int, string, int set or string set.
JSONP is string representing a javascript code that can be parsed.
What is the use you intend for it? What object are you going to store?
Are you invoking an AJAX call to the dynamodb api to retrieve an element and you want that element to follow JSONP pattern? or you wish to call DynamoDB in your server (perhaps using a servlet) and prepare a JSONP object to be sent to the client
I have a requirement where I will receive multiple business objects from the client and my service has to insert/update all of them.
Can I implement a REST webservice which will have a POST method and will accept a list of business objects and will update/insert all of them into the system? I have read that we should use a POST method to create a new entry. Can we use POST method for this kind of scenario wherein we can create/update multiple entries at one go?
My other query is, for a POST method, is it RESTful to return a business object instead of returning a RESPONSE object?
REST is about scalability; scalability is about cachability; cachability is about individual resources, not sets of them. A post probably shouldn't return anything other than a possible redirect to a GET that returns the resource just posted. Data should be fetched with a GET, GET's are cachable. POST, PUT, DELETE are actions, not queries, you don't get data with them other than what they may include to point you at some new resource via response headers.
Yes you can use POST to accept a document that will cause the creation of a list of business objects. It is not the most obvious way to do it, but it can be done RESTfully. See my answer to your other question.
A POST can return a document that represents information about a business object. It can't really return a business object directly, because HTTP doesn't return objects, it returns streams of bytes that can be interpreted using the content-type header.