繁体   English   中英

在App Engine上使用RingoJS读写数据

[英]Reading and writing data using RingoJS on App Engine

好的,我正在创建一个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的可扩展存储系统,因此,它是存储此类数据的最佳选择(或多或少)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM