How to insert a record using the Datastore Viewer admin console using GQL

Is it possible to insert an INSERT or UPDATE object into the data store using Admin> Datastore Viewer.

eg. doing something like

INSERT INTO table VALUES (Foo='Bar') 
+4
source share
3 answers

No, you cannot; GQL is an SQL-like language for extracting entities or keys only.

You can INSERT, UPDATE, or DELETE objects using the data warehouse viewer or application code.

+3
source

Not with GQL, but it is possible to insert INSERT and UPDATE objects using the Datastore Viewer.

In INSERT : after clicking on the data warehouse view tool, click the "Create from the top" tab, select "View", click "Next", fill in the values ​​and click "Save Object".

IN UPDATE . In the data warehouse viewer, click the ID / Name, change the values, and click Save Entity.

+7
source

paste using 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); ?> 
+1
source

Source: https://habr.com/ru/post/955397/


All Articles