I am working to add items to a dynamodb database using python (boto api). I saw examples of people creating items and storing them using the table.new_item method.
Ex:
dynamoConn = boto.connect_dynamodb(aws_access_key_id, aws_secret_access_key)
dTable = dynamoConn.get_table(aws_dynamo_table)
....
item_data = {}
....
dTable.new_item(loc, theNewKey, item_data)
The code runs, I do not find any errors and when tracing through using debugger I do not see any reason why my item, a hash of keys and text values can't be stored.
I read: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html
However I think I may be missing an "update table" function. I'm not seeing one nor can I find an example of one online.
Any ideas?
The new_item method returns an Item object that is ready to be saved to DynamoDB but it doesn't actually save it for you. Once you are ready to save the item, you need to call the save (UpdateItem) or put (PutItem) method of the Item object.
Related
I am trying to make a Flutter and Firebase fitness application that saves runs a user logs. The runs are saved in an array called 'runs' in the Firestore database. Each document in my database represents a different user's runs, so the 'runs' array is a field found within each user's document. I have been trying to delete only a specific child of 'runs' but have had no luck. Does anyone know how to do this?
Here is my code for the delete function:
final CollectionReference runCollection = Firestore.instance.collection('runs')
Future deleteRun(dynamic runToDelete) async {
return await runCollection.document(uid).setData({
'runs': FieldValue.arrayRemove([runToDelete])
});
}
When I run this, I get no errors but nothing happens in the database.
I have also tried FieldValue.delete() but have not been able to isolate a specific index of 'runs' to delete without deleting the entire array.
Here is a picture of my firestore database:
Firestore.instance.collection(collection name).document(your document id).updateData({"array name": FieldValue.arrayRemove([delete object/array])}).than((value){print("delete");}).catchError((error){print(error);});
FieldValue.delete() only works when you know the entire contents of the array item to delete. It does not work with indexes, nor does it work with child values of array items.
What you will have to do instead is read the document, modify the array in memory, then write the modified array back to the document.
The structure for a database I´m building its like a chain, it looks like this:
Click here to see the structure
Where those parts are:
Click here to see what represents each part
So, when I want to add new data to my chain:
Click here to see the new data coming
,in any place I want, I can just easily update their values by updating the datastore.key of the structs: click here to see the update
So, in this case I just need to update b.NextBlock, c.LastBlock, e.LastBlock and e.NextBlock and everything its fine, but lets supposed I want to add more new data Click her to see new data coming
and I don´t want to save the chain if any of that data fail ¿what should I do?
So, the normal thing to think in both cases it's to do it with "client.RunInTransaction" method for each new data so I guarantee that everything was fine,but this its not possible because I can´t get the "datastore.key" when appending data to datastore into "client.RunInTransaction" as documentation says https://godoc.org/cloud.google.com/go/datastore#Transaction.Put (it returns *PendingKey no key itself) and I need to be outside "client.RunInTransaction" in order to get the "datastore.key" of the element and "commit" as documentation says https://godoc.org/cloud.google.com/go/datastore#Commit.Key
So, I want the funtion "put" into "client.RunInTransaction" give me the key of that element when the code is inside "client.RunInTransaction", no after, so I can guarantee that everything was ok with the update, because if I have the key after, the next appending may fail and I don´t want my data to save it
First create the new data entity separately, to get its key. The LastBlock and NextBlock properties would still be empty at this point.
Only after you have the entity's key use the transaction to perform the entity's insertion in the list, in which you only update the key references for that entity as well as the previous and the next entities (if any) in between which the entity is to be inserted.
I am looking to create a feature whereby a User can download any available documents related to the item from a tab on the PDP.
So far I have created a custom record called Documentation (customrecord_documentation) containing the following fields:
Related item : custrecord_documentation_related_item
Type : custrecord_documentation_type
Document : custrecord_documentation_document
Description : custrecord_documentation_description
Related Item ID : custrecord_documentation_related_item_id
The functionality works fine on the backend of NetSuite where I can assign documents to an Inventory item. The stumbling block is trying to fetch the data to the front end of the SCA webstore.
Any help on the above would be much appreciated.
I've come at this a number of ways.
One way is to create a Suitelet that returns JSON of the document names and urls. The urls can be the real Netsuite urls or they can be the urls of your suitelet where you set up the suitelet to return the doc when accessed with action=doc&id=_docid_ query params.
Add a target <div id="relatedDocs"></div> to the item_details.tpl
In your ItemDetailsView's init_Plugins add
$.getJSON('app/site/hosting/scriptlet.nl...?action=availabledoc').
then(function(data){
var asHtml = format(data); //however you like
$("#relatedDocs").html(asHtml);
});
You can also go the whole module route. If you created a third party module DocsView then you would add DocsView as a child view to ItemDetailsView.
That's a little more involved so try the option above first to see if it fits your needs. The nice thing is you can just about ignore Backbone with this approach. You can make this a little more portable by using a service.ss instead of the suitelet. You can create your own ssp app for the function so you don't have to deal with SCAs url structure.
It's been a while, but you should be able to access the JSON data from within the related Backbone View class. From there, within the return context, output the value you're wanting to the PDP. Hopefully you're extending the original class and not overwriting / altering the core code :P.
The model associated with the PDP should hold all the JSON data you're looking for. Model.get('...') sort of syntax.
I'd recommend against Suitelets for this, as that's extra execution time, and is a bit slower.
I'm sure you know, but you need to set the documents to be available as public as well.
Hope this helps, thanks.
I have the following hierarchy on firebase, some data are hidden for confidentiality:
I'm trying to get a list of videos IDs (underlines in red)
I only can get all nodes, then detect their names and store them in an array!
But this causes low performance; because the dataSnapshot from firebase is very big in my case, so I want to avoid retrieving all the nodes' content then loop over them to get IDs, I need to just retrieve the IDs only, i.e. without their nested elements.
Here's my code:
new Firebase("https://PRIVATE_NAME.firebaseio.com/videos/").once(
'value',
function(dataSnapshot){
// dataSnapshot now contains all the videos ids, lines & links
// this causes many performance issues
// Then I need to loop over all elements to extract ids !
var videoIdIndex = 0;
var videoIds = new Array();
dataSnapshot.forEach(
function(childSnapshot) {
videoIds[videoIdIndex++] = childSnapshot.name();
}
);
}
);
How may I retrieve only IDs to avoid lot of data transfer and to avoid looping over retrived data to get IDs ? is there a way to just retrive these IDs directly ?
UPDATE: There is now a shallow command in the REST API that will fetch just the keys for a path. This has not been added to the SDKs yet.
In Firebase, you can't obtain a list of node names without retrieving the data underneath. Not yet anyways. The performance problems can be addressed with normalization.
Essentially, your goal is to split data into consumable chunks. Store your list of video keys, possible with a couple meta fields like title, etc, in one path, and store the bulk content somewhere else. For example:
/video_meta/id/link, title, ...
/video_lines/id/...
To learn more about denormalizing, check out this article: https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html
It is a bit old, and you probably already know, but in case someone else comes along. You can do this using REST api call, you only need to set the parameter shallow=true
here is the documentation
I'm using AngularFire and have an ng-repeat list with items that contain data specific to the "author" of that item (multiple users can add to the list), such as name, location, etc. I'm not writing that data into the array being iterated over by ng-repeat since it could change in the future. Instead, that author-specific data is store in a different location so the goal is that if the author changes their information, all of it is reflected in the list.
For a contrived example, imagine I'm iterating over a list of books from different authors. That list will contain the book-specific data (such as title, publish date, etc.) but I will also want to display the author's information in the list. Instead of including the author's information directly within the book data, I want to simply reference that author ID, and pull in whatever data is in their profile so if they change their name, it'll reflect the changes in all of their book listings.
That means I'm left to make async calls to Firebase to retrieve that information for each list item via a template function, such as {{getAuthorName(authorId)}}. The only problem is that they're async calls and the template function evaluates before the data is available.
I've looked into how to accomplish but have yet to find a solution that accommodates what I need. The answers here seem close, but they appear to no longer work in Angular >= 1.2.0 and they don't account for having to return different data for each template function call.
Update
Here is a JSFiddle with what I have now. I've made some progress, but all that's being returned now is the promise object as expected. I'm not sure how to implement .then in this scenario to get the actual value.
Any help would be great.
You can make use of $firebaseObject and then store that in an object to make sure it doesn't get hit again. like so:
var authors = {};
$scope.getAuthorName = function(authorId){
if(!authors[authorId]){
var authorRef = new Firebase(fburl + "/authors/" + authorId);
authors[authorId] = $firebaseObject(authorRef);
}
return authors[authorId];
};
You can see the working fiddle here: http://jsfiddle.net/0rcdpq47/