简体   繁体   中英

Reading and writing data using RingoJS on App Engine

Okay, I'm creating a RingoJS project and hosting it on Google App Engine. Now App Engine allows you to use java.io.FileInputStream to read data from the filesystem, but it doesn't allow you to use java.io.FileOutputStream to write data to the filesystem.

The data I would like to store is simple markdown for blog posts. Now I'm trying to learn how to store data using the High Replication Datastore API provided by App Engine, but I'm still confused as to how to do so.

If I'm not wrong, I need to do something along the following lines (in 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");

Is what I'm doing correct? Is there any other way to store persistent data easily? I only need to read and write data. I don't need queries.

Yes, what you're doing looks fine. The datastore is App Engine's scalable storage system, as such it's the best (and more or less only) option for storing data like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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