2

好的,我正在創建一個RingoJS項目並將其託管在Google App Engine上。現在,App Engine允許您使用java.io.FileInputStream從文件系統讀取數據,但它不允許您使用java.io.FileOutputStream將數據寫入文件系統。在App Engine上使用RingoJS讀取和寫入數據

我想存儲的數據是博客文章的簡單降價。現在我正試圖學習如何使用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"); 

是我在做什麼正確的嗎?有沒有其他方式可以輕鬆存儲持久數據?我只需要讀寫數據。我不需要查詢。

回答

1

是的,你在做什麼看起來很好。數據存儲是App Engine的可擴展存儲系統,因此它是存儲這種數據的最佳選擇(或多或少)。