好的,我正在创建一个 RingoJS 项目并将其托管在 Google App Engine 上。现在 App Engine 允许您使用java.io.FileInputStream
从文件系统读取数据,但不允许您使用java.io.FileOutputStream
向文件系统写入数据。
我想存储的数据是博客文章的简单降价。现在我正在尝试学习如何使用 App Engine 提供的 High Replication Datastore API 存储数据,但我仍然对如何做到这一点感到困惑。
如果我没记错的话,我需要按照以下几行(在 JavaScript 中)做一些事情:
// Get the High Replication Datastore API
importPackage(com.google.appengine.api.datastore);
// Create a new datastore
var datastore = DatastoreServiceFactory.getDatastoreService();
// Save the blog post
var blogPost = new Entity("BlogPost", uid, author.getKey());
blogPost.setProperty("markdown", markdown);
datastore.put(blogPost);
// Create the key for the blog post
var key = KeyFactory.createKey("BlogPost", uid, author.getKey());
// Getting the entity
var blogPost = datastore.get(key);
// Reading the properties
var markdown = blogPost.getProperty("markdown");
我在做什么正确吗?有没有其他方法可以轻松存储持久数据?我只需要读写数据。我不需要查询。