0
votes

I have a Entity with ~50k rows in Google Cloud Datastore, the stand alone not GAE. I am starting development with GAE and would like to query this existing datastore without having to import it to GAE. I have been unable to find a way to connect to an existing datastore Kind.

Basic code altered from Hello World and other guides im trying to get working as a POC.

import webapp2
import json
import time
from google.appengine.ext import ndb

class Product(ndb.Model):
type = ndb.StringProperty()

@classmethod
def query_product(cls):
    return ndb.gql("SELECT * FROM Product where name >= :a LIMIT 5 ")

class MainPage(webapp2.RequestHandler):
def get(self):
    self.response.headers['Content-Type'] = 'text/plain'

    query = Product.query_product()

    self.response.write(query)


app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)

Returned Errors are

TypeError: Model Product has no property named 'name'

Seems obvious that its trying to use a GAE datastore with the kind Product instead of my existing Datastore with Product already defined, But I cant find how to make that connection.

3

3 Answers

1
votes

There is only one Google Cloud Datastore. App Engine does not have a datastore of its own - it works with the same Google Cloud Datastore.

All entities in the Datastore are stored for a particular project. If you are trying to access data from a different project, you will not be able to see it without going through special authentication.

0
votes

I'm not too certain what it is you're trying to accomplish when you say that you would like to query this existing datastore without having to import it to GAE. I'm guessing that you have project A with the datastore with 50k rows, and you're starting project B. And you want to access the project A datastore from project B. If this is the case, and if you're trying to access the datastore from a different project, then maybe this previous answer that mentions remote api can help you.

0
votes

Below is working code. I was pretty close at the time I made this original post but the reason I was getting no data back was because I was running my App locally. As soon as I actually deployed my code to App Engine it pulled from Datastore no problem.

import webapp2
import json
import time
from google.appengine.datastore.datastore_query import Cursor
from google.appengine.ext import ndb



class Product(ndb.Model):
    name = ndb.StringProperty()


class MainPage(webapp2.RequestHandler):
    def get(self):
    self.response.headers['Content-Type'] = 'text/plain'


    query = ndb.gql("SELECT * FROM Product where name >= 'a' LIMIT 5 ")
    output = query.fetch()

    #query = Product.query(Product.name == 'zubo - pre-owned - nintendo ds')
    #query = Product.query()
    #output = query.fetch(10)
    self.response.write(output)


app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)