google-cloud-datastore

A convenient way to preload data in development environment datastore

拥有回忆 提交于 2019-12-04 18:54:05
I'm developing an application on Google App Engine using Maven. When I run the local server I would like to have some data preloaded in the datastore, such as the local user table. The server puts the datastore file under the WEB-INF/appengine-generated of the target directory and it is cleaned before every build. Is there a convenient way to do so? You have a couple of options: a. backup and reload local_db.bin in your build steps b. use the datastore.backing_store system property with: dev_appserver.sh --jvm_flag= -Ddatastore.backing_store=\path\to\local_db.bin 来源: https://stackoverflow.com

GAE datastore list property serialization

萝らか妹 提交于 2019-12-04 18:30:38
I've watched this video from Google I/O 2009: http://www.youtube.com/watch?v=AgaL6NGpkB8 where Brett shows microblogging example. He describes two datastore schemas: first one: class Message(db.Model): sender = db.StringProperty() body = db.TextProperty() receivers = db.StringListProperty() and second one: class Message(db.Model): author = db.StringProperty() message = db.TextProperty() class MessageIndex(db.Model) receivers = db.StringListProperty() And he says that in first example datastore has to serialize/deserialize receivers property every time we query messages by receiver, and in

One-to-many relationships in datastore

ぐ巨炮叔叔 提交于 2019-12-04 17:49:41
There is a nice explanation of 1-to-many relationships in datastore here by Rafe Kaplan. I tried to adapt that to a simpler case of User and Venue . So user can go to many restaurants; and I want to print the user email and the restaurants the user went to: class User(db.Model): userEmail = db.StringProperty() class Venue(db.Model): user = db.ReferenceProperty(User, collection_name="venues") venue = db.StringProperty() class OneToMany(webapp.RequestHandler): def get(self): scott = User(userEmail="scott@example.com") scott.put() Venue(user=scott, venue="club1").put() Venue(user=scott, venue=

Set an entity kind name different from a class name

拟墨画扇 提交于 2019-12-04 17:27:25
Is there any way how to set a kind name different from a class name used in my Google App Engine? I am using Java and JDO to access a datastore. There a question about the similar issue in Python. It seems answered. Set a kind name independently of the model name (App Engine datastore) Ooops... It was quite easy to achieve: @PersistenceCapable(table = "person") public class PersonEntity { // ... } 来源: https://stackoverflow.com/questions/7616158/set-an-entity-kind-name-different-from-a-class-name

How to fetch the latest data in GAE Python NDB

半世苍凉 提交于 2019-12-04 17:25:58
I am using GAE Python. I have two root entities: class X(ndb.Model): subject = ndb.StringProperty() grade = ndb.StringProperty() class Y(ndb.Model): identifier = ndb.StringProperty() name = ndb.StringProperty() school = ndb.StringProperty() year = ndb.StringProperty() result = ndb.StructuredProperty(X, repeated=True) Since google stores our data across several data centers, we might not get the most recent data when we do a query as shown below(in case some changes have been "put"): def post(self): identifier = self.request.get('identifier') name = self.request.get('name') school = self

Appengine ID/Name vs WebSafeKey

拜拜、爱过 提交于 2019-12-04 16:09:47
When writing the endpoints in java, for finding items by their keys, should I use the Id or the webSafeString of the key? In what situations does this matter? It's up to you. Do the entities have parents? Then you probably want to use the urlsafe representation as a single string will contain the full path to the entity. If you used an ID instead - you would somehow need to manually include the IDs of all parents up to the root. No parents & IDs are numeric / alphanumeric? Then just use the IDs as they look cleaner (again, this is not a rule and is completely up to you). No parents but IDs

GAE Entity group / data modeling for consistency and performance

徘徊边缘 提交于 2019-12-04 15:58:09
问题 As a continuation of in this post, this is a bit of a capstone-style question to solidify my understanding of gae-datastore and get some critiques on my data modeling decisions. I'll be modifying he Jukebox example created by @Jimmy Kane to better reflect my real world case. In the original setup, imagine that you have a jukebox with queues per room let's say. And people are queueing songs to each queue of each jukebox. J=Jukebox, Q=queue, S=Song Jukebox / | \ Q1 Q2 Q3 / | \ | \ S1 S2 S3 S4

Google Datastore problem with query on *User* type

…衆ロ難τιáo~ 提交于 2019-12-04 15:56:50
问题 On this question I solved the problem of querying Google Datastore to retrieve stuff by user (com.google.appengine.api.users.User) like this: User user = userService.getCurrentUser(); String select_query = "select from " + Greeting.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("author == paramAuthor"); query.declareParameters("java.lang.String paramAuthor"); greetings = (List<Greeting>) query.execute(user); The above works fine - but after a bit of messing around I

How to query datastore when using ReferenceProperty?

微笑、不失礼 提交于 2019-12-04 15:46:33
I am trying to understand the 1-to-many relationships in datastore; but I fail to understand how query and update the record of a user when the model includes ReferenceProperty . Say I have this model: class User(db.Model): userEmail = db.StringProperty() userScore = db.IntegerProperty(default=0) class Comment(db.Model): user = db.ReferenceProperty(User, collection_name="comments") comment = db.StringProperty() class Venue(db.Model): user = db.ReferenceProperty(User, collection_name="venues") venue = db.StringProperty() If I understand correctly, the same user, uniquely identified by userEmail

GAE w/ Objectify - Can you query a HashMap?

拥有回忆 提交于 2019-12-04 14:04:15
In GAE, when using Objectify, can you query a HashMap? If so how would would you write it? ofy().load().type(MyClass.class).filter("hashMapfieldName", "keyQueryinggFor").list(); Does not seem to work where the hashMapfieldName is a HashMap<String, String> . I am looking to find entities where hashMapfieldName contains a certain key. Just like embedded classes, Objectify converts Map<String, String> to the low-level EmbeddedEntity object, which is not indexible. However, if you @Index your Map field (or embedded class field), Objectify will create a synthetic index that lets you query anyways.