app-engine-ndb

Is there a way to specify a projection for ndb.get_multi()?

余生颓废 提交于 2021-02-07 18:42:49
问题 Using NDB, it is possible to specify a projection for a query, allowing to limit the number of properties that are retrieved for the entities that match the query. However, I couldn't find anything in the documentation about how to specify a projection when using ndb.get_multi() , which always fetches complete entities. Is there a way to fetch only certain properties when using ndb.get_multi() ? 回答1: No, the projection feature only works for queries. There would be no advantage (in terms of

How do appengine cursors work?

给你一囗甜甜゛ 提交于 2021-02-06 11:43:51
问题 I'm using both ndb and search-api queries in my python appengine project. The only official docs on cursors I can find: https://cloud.google.com/appengine/docs/python/datastore/query-cursors https://cloud.google.com/appengine/docs/python/search/cursorclass Following things are unclear for me: What is cursor time-to-live ? Can I expose year-old cursors ? How would cursor pagination behave in case items are added/removed from original collection? (+ if cursor points to particular record, what

How to check if NDB model is valid

◇◆丶佛笑我妖孽 提交于 2021-01-28 05:11:06
问题 I have a model class like: class Book(ndb.Model): title = ndb.StringProperty(required=True) author = ndb.StringProperty(required=True) and I have some code using this: book = Book() print book >> Book() book_key = book.put() >> BadValueError: Entity has uninitialized properties: author, title Is there a way to check if model is valid before saving it? And finding out which property is invalid and the type of error (e.g. required). And if you have structured property how will this work then?

How do I get the key for the current record in GAE ndb in a Python for loop?

我与影子孤独终老i 提交于 2020-02-03 16:25:13
问题 I currently have a web page that presents a list of records from a datastore with an edit link. I want to convert this from db. to ndb. I am a Python and GAE newbie. The current code = <tbody> {% for listtype in listtypes %} <tr> <td> {{ listtype.ListTypeName }} </td> <td><a href ="/listtypes/edit/{{ listtype.key().id() }}">edit </a></td> </tr> {% endfor %} </tbody> Then on the .py side, I have: def post(self, listtype_id): iden = int(listtype_id) listtypes = db.get(db.Key.from_path(

How do I get the key for the current record in GAE ndb in a Python for loop?

放肆的年华 提交于 2020-02-03 16:24:11
问题 I currently have a web page that presents a list of records from a datastore with an edit link. I want to convert this from db. to ndb. I am a Python and GAE newbie. The current code = <tbody> {% for listtype in listtypes %} <tr> <td> {{ listtype.ListTypeName }} </td> <td><a href ="/listtypes/edit/{{ listtype.key().id() }}">edit </a></td> </tr> {% endfor %} </tbody> Then on the .py side, I have: def post(self, listtype_id): iden = int(listtype_id) listtypes = db.get(db.Key.from_path(

app engine datastore transaction exception

寵の児 提交于 2020-01-30 12:08:16
问题 In app engine transactions documentation I have found the following note: Note: If your app receives an exception when submitting a transaction, it does not always mean that the transaction failed. You can receive Timeout, TransactionFailedError, or InternalError 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

ndb verify entity uniqueness in transaction

隐身守侯 提交于 2020-01-25 18:43:54
问题 I've been trying to create entities with a property which should be unique or None something similar to: class Thing(ndb.Model): something = ndb.StringProperty() unique_value = ndb.StringProperty() Since ndb has no way to specify that a property should be unique it is only natural that I do this manually like this: def validate_unique(the_thing): if the_thing.unique_value and Thing.query(Thing.unique_value == the_thing.unique_value).get(): raise NotUniqueException This works like a charm

Client Library for Cloud Datastore on App Engine - NDB or google-cloud-datastore

浪尽此生 提交于 2020-01-22 12:59:05
问题 Per Google's documentation, it seems like I have two main options for connecting to Datastore using Python: App Engine's NDB Datastore library, and the Google Cloud Datastore API for Python. I'm currently on App Engine (Standard), but I'd like to structure my app such that it can grow beyond if required, likely via a move to Compute Engine. With that in mind, which library should I use? App engine's documentation states that NDB can be used, but it doesn't seem to be very actively developed

Putting models in a callback function from ctypes library

自作多情 提交于 2020-01-16 18:34:28
问题 I am trying to setup an application based on the Google App Engine using the Managed VM feature. I am using a shared library written in C++ using ctypes cdll.LoadLibrary('./mylib.so') which registers a callback function CB_FUNC_TYPE = CFUNCTYPE(None, eSubscriptionType) cbFuncType = CB_FUNC_TYPE(scrptCallbackHandler) in which i want to save data to the ndb datastore def scrptCallbackHandler(arg): model = Model(name=str(arg.data)) model.put() I am registering a callback function in which i want

ndb.OR makes query costs more

自古美人都是妖i 提交于 2020-01-16 17:58:25
问题 Using AppEngine appstats I profiled my queries, and noticed that although the docs say a query costs one read, queries using ndb.OR (or .IN which expands to OR), cost n reads (n equals the number of OR clauses). eg: votes = (Vote.query(ndb.OR(Vote.object == keys[0], Vote.object == keys[1])) .filter(Vote.user_id == user_id) .fetch(keys_only=True)) This query costs 2 reads (it matches 0 entities). If I replace the ndb.OR with Vote.object.IN, the number of reads equals the length of array I pass