google-cloud-datastore

How to structure movies database and user choices?

倖福魔咒の 提交于 2019-11-30 10:23:20
I would like to create movies database, where user will be able to mark movies he/she watched and liked: class Movies(ndb.Model): watched = ndb.UserProperty() liked = ndb.UserProperty() Will that work? I use Google accounts. How should I choose later all movies user liked? Upd . I've followed systempuntoout approach and use the following code to save user choices: user = users.get_current_user() if user: userschoices = models.UsersChoices( movie=ndb.Key(models.Movies, movie_id), # TODO: what if movie_id is wrong? watched=True, user_id=user.user_id() ) try: userschoices.put() self.response.out

Google Datastore queries and eventual consistency

强颜欢笑 提交于 2019-11-30 09:59:04
I would like to confirm my understanding of eventual consistency in the Google datastore. Suppose that I have an entity defined as follows (using ndb): class Record(ndb.Model): name = ndb.StringProperty() content = ndb.BlobProperty() I think I understand Scenarios 1, but I have doubts about Scenarios 2 and 3, so some advice would be highly appreciated. Scenario 1: I insert a new Record with name "Luca" and a given content. Then, I query the datastore: qry = Record.query(name=="Luca") for r in qry.iter(): logger.info("I got this content: %r" % r.content) I understand that, due to eventual

How to get the number of rows in a table in a Datastore?

给你一囗甜甜゛ 提交于 2019-11-30 09:26:08
In many cases, it could be useful to know the number of rows in a table (a kind) in a datastore using Google Application Engine. There is not clear and fast solution . At least I have not found one.. Have you? David Underhill You can efficiently get a count of all entities of a particular kind (i.e., number of rows in a table) using the Datastore Statistics . Simple example: from google.appengine.ext.db import stats kind_stats = stats.KindStat().all().filter("kind_name =", "NameOfYourModel").get() count = kind_stats.count You can find a more detailed example of how to get the latest stats here

What's the max length of a ListProperty?

和自甴很熟 提交于 2019-11-30 09:13:44
How many items can be stored in a ListProperty? Is there a limit? Entities are limited to 1MB in size (when encoded as a Protocol Buffer), so this provides a practical limit on the size of a list. Further, if the list is indexed, you're limited to 5000 entries before you get an exception because your entity has too many index rows. In my experience you will get MemoryError exceptions deserializing ListProperties before you hit a hard limit. That used to happen to me with 5,000 to 10,000 Key entities in the list. Also, entities are limited to 5,000 indexed properties so 5,000 is a good maximum.

How to query parent entity from child entity in Google App Engine (Python) NDB/Datastore?

倖福魔咒の 提交于 2019-11-30 09:01:57
My question is very fundamental, I want to know straight forward and right way to access attribute values of parent entity from a child in App Engine Python. For example I have following model schema. I am using Python 2.7 and NDB. class Gallery(ndb.Model): category = ndb.StringProperty() title = ndb.StringProperty() subtitle = ndb.StringProperty() class Image(ndb.Model): blob_key = ndb.BlobKeyProperty() title = ndb.StringProperty() gallery = ndb.StringProperty() is_slider = ndb.StringProperty() Here "Gallery" is parent of "Image". They form an entity group Exhibition=>Gallery=>Image. I want

GAE transaction failure and idempotency

有些话、适合烂在心里 提交于 2019-11-30 08:59:58
The Google App Engine documentation contains this paragraph: Note: If your application receives an exception when committing a transaction, it does not always mean that the transaction failed. You can receive DatastoreTimeoutException, ConcurrentModificationException, or DatastoreFailureException exceptions in cases where transactions have been committed and eventually will be applied successfully. Whenever possible, make your Datastore transactions idempotent so that if you repeat a transaction, the end result will be the same. Wait, what? It seems like there's a very important class of

Read delay in App Engine Datastore after put()

江枫思渺然 提交于 2019-11-30 08:29:26
I write a code for a blog/news site. Main page has 10 most recent articles and also there is an archive section with all articles sorted by modification time descending. In archive section I use pagination based on cursors and I cache results starting from the second page as pages are changed only when new article is published or existing goes to drafts for some reason. Every page has 10 articles. So when a user hits an archive page with some number (not the first one) memcache is checked for that page number results first. If the page is not there, memcache is checked for the cursor for that

How do you upload data in bulk to Google App Engine Datastore?

纵饮孤独 提交于 2019-11-30 07:32:06
I have about 4000 records that I need to upload to Datastore. They are currently in CSV format. I'd appreciate if someone would point me to or explain how to upload data in bulk to GAE. You can use the bulkloader.py tool: The bulkloader.py tool included with the Python SDK can upload data to your application's datastore. With just a little bit of set-up, you can create new datastore entities from CSV files. I don't have the perfect solution, but I suggest you have a go with the App Engine Console . App Engine Console is a free plugin that lets you run an interactive Python interpreter in your

How do you use list properties in Google App Engine datastore in Java?

六眼飞鱼酱① 提交于 2019-11-30 07:31:59
问题 An object to be placed in the datastore will have a set of tags. public class Model { List<String> tagList ... } In Python, the Google App Engine has the notion of list properties. What is the equivalent notion in Java (if it exists) and how would you use list properties in Java, in JPA and/or in JDO? 回答1: See my blog post exactly on this: Efficient Keyword Search with Relation Index Entities and Objectify for Google Datastore. It talks about implementing search with list properties using

db.ReferenceProperty() vs ndb.KeyProperty in App Engine

五迷三道 提交于 2019-11-30 06:54:11
ReferenceProperty was very helpful in handling references between two modules. Fox example: class UserProf(db.Model): name = db.StringProperty(required=True) class Team(db.Model): manager_name = db.ReferenceProperty(UserProf, collection_name='teams') name = db.StringProperty(required=True) To get 'manager_name' with team instance, we use team_ins.manager_name. To get 'teams' which are managed by particular user instance, we use user_instance.teams and iterate over. Doesn't it look easy and understandable? In doing same thing using NDB, we have to modify db.ReferenceProperty(UserProf,