Using python, I'm just learning with regard to GAE and the datastore so am
probably going about this all wrong and I'd love some advice from the more
experienced.
As an exercise I wanted to emulate a graph database structure using ndb.
However, I'm having trouble accessing entities when all I have is a string
value for the key...
Because this is an API I am using messages...
class NewItemReturnMessage(messages.Message):
key_string = messages.StringField(1, required=True)
class NewVertexRequestMessage(messages.Message):
parameters = messages.StringField(1)
class Vertex(ndb.Model):
parameters = ndb.JsonProperty(repeated=True)
class VertexIndex(ndb.Model):
inEdges = ndb.KeyProperty(repeated=True)
outEdges = ndb.KeyProperty(repeated=True)
class Edge(ndb.Model):
parameters = ndb.JsonProperty(repeated=True)
class EdgeIndex(ndb.Model):
inVert = ndb.KeyProperty(required=True)
outVert = ndb.KeyProperty(required=True)
So to create a new Vertex through the API I have the following method...
@endpoints.method(NewVertexRequestMessage, NewItemReturnMessage,
name='vertex.generate',
path='vertex',
http_method='POST')
def generate_vertex(self, request):
if request.parameters != "" and request.parameters != None:
newVertex = Vertex(parameters = request.parameters.split(','))
else:
newVertex = Vertex()
vertex_key = newVertex.put()
newVertexIndex = VertexIndex(parent=vertex_key)
vertexIndex_key = newVertexIndex.put()
retMessage = NewItemReturnMessage(key = str(vertex_key))
return retMessage
notice that I'm returning a string object for my vertex_key because there
is no messages.KeyField
When I want to connect two vertices through the API I need to supply the
key for each one but I'm having no success being able to retrieve the
entity based on supplying a string value for the key. I'm trying something
like this...
inVert = Vertex.query(Vertex.__key__ == request.inVertKey)
Am I even in the ball park?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.