Hi Sajid,
Unfortunately there is no automatic way to migrate a Cloud SQL database to Datastore. The general process for migrating is as follows:
Map your relational model to datastore kinds and entities
[Optional] Download your relational database as csv
Write a script using one of our Cloud Datastore Client Libraries that would transfer your data from Cloud SQL or the csv in step 2 to Datastore
If you have a large database, it would speed up the migration process by hosting your script on App Engine.
If you require assistance in writing your script for migrating relational database to Datastore it is recommended to post your complete question to Stack Overflow using one of our supported tags, as your question will receive a lot more attention there.
<?php
require __DIR__ . '/../../vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Entity;
$projectId = "__my projectID__";
$datasetId = $projectId;
$datastore = new DatastoreClient(['projectId' => $projectId]);
function llist($datastore){
$query = $datastore->query()
->kind('keypad_research')
->start($cursor);
$results = $datastore->runQuery($query);
$entries = [];
$count = 0;
foreach ($results as $entity) {
$count++;
}
echo $count; // this shows me '0' results even when I have 2 entities.
}
llist($datastore);
?>
Hello Sajid,
I have reproduced your code as below with some modification after executing the commands and PHP code outlined here.
$datasetId = $projectId;
$datastore = new DatastoreClient(['projectId' => $projectId]);
function llist($datastore){
$query = $datastore->query()
->kind('Task');
$results = $datastore->runQuery($query);
$entries = [];
$count = 0;
foreach ($results as $entity) {
$count++;
}
echo $count; // this shows me '1' results when I have used Kind('Task') and shows me '0' for Kind('Task1') .
}
llist($datastore);
The kind, ‘Task’ was defined in the PHP code of the above mentioned link as a result when the modified version of your code was executed it has shown the result 1. When the kind, ‘Task’ was modified with ‘Task1’ it has shown the result 0.
From the above observation, it is appearing the kind, 'keypad_research' that you used may not exist or your typed it wrong. In addition the variable $cursor is not defined in your code which I removed during reproduction as it was showing the following error:
PHP Notice: Undefined variable: cursor in /home/.../php/index.php on line 17
As it was mentioned earlier, If your issue is not a platform issue but rather a problem with how you've configured your code, although you're not sure what it may be specifically, you should post to StackOverflow and community of developers will assist you.