GAE NDB Datastore new feature: Access Datastore entities from other GAE app

后端 未结 1 1849
耶瑟儿~
耶瑟儿~ 2021-02-04 13:31

Reading the new documentation of GAE NDB Datastore: https://cloud.google.com/appengine/docs/python/ndb/modelclass#class_methods

get_by_id(id, parent         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 14:25

    Currently, ndb doesn't use the Cloud Datastore API and in its normal mode of operation can't connect to another app's Datastore - it connects natively to the Datastore of the app the code is running on.

    You can, however, use the remote api to have ndb connect to the Datastores of different apps from the development environment.

    There is currently [an open Feature Request in the Public Issue Tracker for App Engine for the possibility of accessing multiple Datastores from a single app. Feel free to post a Feature Request for ndb specifically, although from the following comments in the source it appears this is already something that's being worked-on:

     current_app_id = os.environ.get('APPLICATION_ID', None)
      if current_app_id and current_app_id != app_id:
        # TODO(pcostello): We should support this so users can connect to different
        # applications.
        raise ValueError('Cannot create a Cloud Datastore context that connects '
                         'to an application (%s) that differs from the application '
                         'already connected to (%s).' % (app_id, current_app_id))
      os.environ['APPLICATION_ID'] = app_id
    

    0 讨论(0)
提交回复
热议问题