好的,我正在创建一个RingoJS项目并将其托管在Google App Engine上。现在,App Engine允许您使用java.io.FileInputStream从文件系统读取数据,但不允许您使用java.io.FileOutputStream将数据写入文件系统。

我想存储的数据是博客文章的简单减价。现在,我正在尝试学习如何使用App Engine提供的High Replication数据存储区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的可扩展存储系统,因此,它是存储此类数据的最佳选择(或多或少)。

07-25 23:37
查看更多