google-cloud-datastore

Getting The Most Recent Data Item - Google App Engine - Python

筅森魡賤 提交于 2020-01-04 05:36:14
问题 I need to retrieve the most recent item added to a collection. Here is how I'm doing it: class Box(db.Model): ID = db.IntegerProperty() class Item(db.Model): box = db.ReferenceProperty(Action, collection_name='items') date = db.DateTimeProperty(auto_now_add=True) #get most recent item lastItem = box.items.order('-date')[0] Is this an expensive way to do it? Is there a better way? 回答1: If you are going to iterate over a list of boxes, that is a very bad way to do it. You will run an additional

Ever see duplicate IDs when using Google App Engine and ndb?

爷,独闯天下 提交于 2020-01-04 04:25:06
问题 class Entries(ndb.Model): description = ndb.StringProperty() seqid = ndb.IntegerProperty() link = ndb.StringProperty() group = ndb.StringProperty() timestamp = ndb.StringProperty() referrals = ndb.StringProperty(repeated=True) The two entries in the picture are created by two different users. The user is the parent of the Entry. I get a duplicate ID on production but not on local. Also, it's always this same id number (but it is certainly not hard coded anywhere) As the parent is the user, i

Got Null when querying datastore by key

拟墨画扇 提交于 2020-01-03 18:56:30
问题 I have two models, Book and Chapter, in a one-to-many relationship. I manually create the keys for both Book and Chapter. To persist, I create a book object then add an instance of chapter to it and then persist book. This works fine, as I see them in the datastore. Now when I try to fetch a chapter from the datastore by key, I get a null object. Here is how the keys look in the datastore: Under Book: name/id = 123 chapters = [Book(123)/Chapter("abc")] Under Chapter: name/id = abc I created

Using low level api for datastore in google app engine ? is it bad?

非 Y 不嫁゛ 提交于 2020-01-03 13:17:08
问题 There is little documentation on how to use the low level api for datastore and quite a lot on JPA and JDO and how it translates to it. My question is: is there any advantage in coding against the JPA or JDO specs instead of accessing directly the low level api for datastore ? From an initial look, it seems simple and straight forward but I am not sure if there are good reasons why not to do it. Thanks Cx 回答1: There is nothing wrong with using the low level API directly. If you want something

What happens to child datastore objects after deleting the ancestor?

僤鯓⒐⒋嵵緔 提交于 2020-01-03 09:07:10
问题 I want to understand the parent/child (ancestor paths) relationship found in the Google AppEngine datastore that wasn't mentioned in the online documentation. What happens to children objects when the parent is deleted? Do child objects also get deleted? Do they become orphaned without a parent? If so how would you query for them? Google Help Doc regarding Ancestor Paths: https://cloud.google.com/appengine/docs/go/datastore/entities#Go_Ancestor_paths Thanks! ~Todd 回答1: Child entities do not

Partly update App Engine entity

懵懂的女人 提交于 2020-01-03 05:55:14
问题 I'm building a sync engine with App Engine and when I receive data from the client I want to store an object but I don't care if it already exists or not. It works nice today if I always send all properties from the client when updating. But I want... some internal properties not to be known by the client and still survive the update the client to be able to only send the changed values avoid fetching all objects before updating them as there can be quite few objects that need updates Do I

How to filter() for different items?

半城伤御伤魂 提交于 2020-01-03 05:52:07
问题 This is a follow up to my previous question. I am using the same model class Item(db.Model): ... glam = db.StringProperty() casual = db.StringProperty() speaking = db.StringProperty() and assume that I have 2 items and 1 is tagged "glam" the other tagged "speaking". If I filter like this query.filter("glam", "glam") query.filter("speaking"), "speaking") the filter returns none because this looks for 1 item tagged "glam" and "speaking". How do I filter for separate items? Update Item table may

Django nonrel Query confusion

可紊 提交于 2020-01-03 04:29:06
问题 I'm creating a practice django-nonrel project hosted on Google AppEngine to get some familiarity with Django and the AppEngine Platform, but am running into a perplexing query issue. Here is my models.py: class Character(models.Model): name = models.CharField(max_length=200) url_name = models.CharField(max_length=200) def save(self, *args, **kwargs): self.url_name = self.name.replace(" ", "-").lower() super(Character, self).save(*args, **kwargs) # Call the "real" save() method. def __unicode_

Google App Engine singletons (Python)

◇◆丶佛笑我妖孽 提交于 2020-01-02 19:46:29
问题 The standard way of doing singletons in Python is class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance However, this doesn't work on App Engine, since there are may be many servers and we would get one instance per server. So how would we do it for an app engine entity? Something like: class MySingleton(db.models): def __init__(self): all = MySingleton.all()

How to update 400,000 GAE datastore entities in parallel?

主宰稳场 提交于 2020-01-02 16:31:53
问题 I have 400,000 entities of a certain type, and I'd like to perform a simple operation on each of them (adding a property). I can't process them serially because it would take forever. I don't want to use the MapReduce library because it is complicated and overwhelming. Basically I'd like to create 100 tasks on the taskqueue, each task taking a segment of ~4,000 entities and performing this operation on each one. Hopefully this wouldn't take more than a few minutes to process all 400k entities