【发布时间】:2012-01-18 12:56:10
【问题描述】:
是否可以使用管理 > 数据存储查看器插入或更新数据存储中的实体。
例如执行类似
INSERT INTO table VALUES (Foo='Bar')
【问题讨论】:
标签: google-app-engine gql
是否可以使用管理 > 数据存储查看器插入或更新数据存储中的实体。
例如执行类似
INSERT INTO table VALUES (Foo='Bar')
【问题讨论】:
标签: google-app-engine gql
不使用 GQL,但可以使用 Datastore Viewer 插入和更新实体。
到INSERT:点击Datastore Viewer后,点击顶部的标签Create,选择Kind,按Next ,填写值并按保存实体。
更新:在数据存储查看器中,单击ID/名称标识符,更改值并按保存实体.
【讨论】:
不,你不能; GQL 是一种类似 SQL 的语言,仅用于检索实体或键。
您可以使用数据存储查看器或从您的应用程序代码插入、更新或删除实体。
【讨论】:
用 Google_Client.php 插入:
<?php
//https://developers.google.com/apis-explorer/#p/datastore/v1beta2/
const APP_NAME='a-test-com';
const SERVICE_ACCOUNT_NAME='511908282087@developer.gserviceaccount.com';
$_PRIVATE_KEY=file_get_contents('data/34672-privatekey.p12');
require_once 'google-api-php-client/Google_Client.php';
$client=new Google_Client();
$credentials=new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/datastore'
),
$_PRIVATE_KEY
);
$client->setAssertionCredentials($credentials);
$postBody=json_encode(array('mode'=>'NON_TRANSACTIONAL','mutation'=>array('upsert'=>array(
array('key'=>array('partitionId'=>array('datasetId'=>'s~'.APP_NAME),
'path'=>array(array('kind'=>'Guestbook',
'name'=>'my_guestbook'
)
)
),
'properties'=>array('guest_name'=>array('stringValue'=>'my name1 my name1'))
)
))));
$httpRequest=new Google_HttpRequest('datastore/v1beta2/datasets/'.APP_NAME.'/commit', 'POST', null, $postBody);
$head=array('content-type'=>'application/json; charset=UTF-8',
'content-length'=>Google_Utils::getStrLen($postBody)
);
$httpRequest->setRequestHeaders($head);
$httpRequest=Google_Client::$auth->sign($httpRequest);
$result=Google_REST::execute($httpRequest);
var_export($result);
?>
【讨论】: