开发者

Delete and Update from google app engine datastore

I use Quercus to run php on google app engine and use GAE LowLevel Api to connect datastore. I need sample php code to CRUD ( Create, Read, Update, Delete ) in datastore. I have Create and Read sample php code.

Create entry to datastore

<?php
import com.google.appengine开发者_高级运维.api.datastore;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.DatastoreServiceFactory;

$entity = new Entity("test"); 
$entity->setProperty('field1','value1');
$entity->setProperty('field2','value2');
$dataService = DatastoreServiceFactory::getDatastoreService();
$dataService->put($entity);
?>

Query to datastore

<?php
import com.google.appengine.api.datastore;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.DatastoreServiceFactory;

$q = new Query('test');
//http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Query.html
$q->addFilter('field1','EQUAL' ,'value1');
$dataService = DatastoreServiceFactory::getDatastoreService();
$prepared = $dataService->prepare($q);
foreach($prepared->asIterable() as $i) {
echo $field1 = $i->getProperty('field1');
echo $field2 = $i->getProperty('field2');
}
?>

Does anyone have any idea how to Delete and Update entries in datastore with php?


the DatastoreService.put() call works for both create and update. the app engine datastore doesn't differentiate between them at the API level. so, the code in your first example should work for update too. just use an existing entity that you got from a get() or query.

as for delete, i haven't tried this, but based on your example code, both $dataService->delete($key) and $dataService->delete($entity->key()) should work, depending on whether you have a key or an entity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜