好的,我正在创建一个 RingoJS 项目并将其托管在 Google App Engine 上。现在 App Engine 允许您使用 java.io.FileInputStream
从文件系统读取数据,但不允许您使用 java.io.FileOutputStream
写入数据到文件系统。
我想存储的数据是博客文章的简单 Markdown 。现在,我正在尝试学习如何使用 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");
我做的对吗?有没有其他方法可以轻松存储持久数据?我只需要读写数据。我不需要查询。
最佳答案
是的,你所做的看起来不错。数据存储区是 App Engine 的可扩展存储系统,因此它是存储此类数据的最佳(或多或少)选项。
关于java - 在 App Engine 上使用 RingoJS 读写数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8464618/