google datastore gql query with limit and offset cursors? -


i'm trying use cursors large result sets. documentation indicates can use cursors gql query using php can't seem work.

has got working? if doesn't work gql query, show me example of how implement this?

    $query = $datastore->gqlquery('select * h_stats field1 = @parm1 , date >= @startdate , date < @enddate limit @limitby offset @cursor', [                                   'bindings' => [                                     'parm1' => '5700305828184064',                                     'startdate' => '1501545600',                                     'enddate' => '1501632000',                                     'limitby' => 10,                                     'cursor' => 'cursor_string_here'                                   ]     ]); 

i figured out. couldn't find possible gql query. it's possible normal query.

hope helps out google docs bad examples.

$datastore = new google\cloud\datastore\datastoreclient([     'projectid' => $projectid, ]);        function cursor_paging($datastore, $querykind, $pagesize, $parm1, $startdate, $enddate, $pagecursor = '')     {          $query = $datastore->query()             ->kind($querykind)             ->filter('field1', '=', $parm1)             ->filter('date', '>=', $startdate)             ->filter('date', '<', $enddate)             ->limit($pagesize)             ->start($pagecursor);                 $result = $datastore->runquery($query);         $nextpagecursor = '';         $entities = [];          foreach ($result $entity) {             $nextpagecursor = $entity->cursor();             $entities[] = $entity;         }         return array(             'nextpagecursor' => $nextpagecursor,             'entities' => $entities         );      } 

this how used function provided in google cloud datastore php docs.

    $pagesize = 500;     $querykind = "your_kind";     $result = cursor_paging($datastore, $querykind, $pagesize, $currentthermostat, $startdate, $enddate);      $countrows = 0;      ($x=0; $x < $pagesize; $x++) {          $counter = 0;          foreach ($result['entities'] $item) {             print($countrows . " " . $item['data']);             $countrows++;             $counter++;         }          $result = cursor_paging($datastore, $querykind, $pagesize, $currentthermostat, $startdate, $enddate, $result['nextpagecursor']);          if ($counter > 0) {             $x = 0;         } else {             $x = $pagesize;  //exit loop when no more results         }     } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -