Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tristansokol/3fe98b6d5a8635b148f55ec123e480ed to your computer and use it in GitHub Desktop.
Save tristansokol/3fe98b6d5a8635b148f55ec123e480ed to your computer and use it in GitHub Desktop.
Datastore php cursor example
//my cursor is set as a url variable ($_GET['albumoffset'])
$albumStore = new \GDS\Store('Tracks');
$obj_store->query("SELECT * FROM Albums");
$obj_store->setCursor(rawurldecode($_GET['albumoffset']));
$entity = $obj_store->fetchPage(1);
//do stuff with my new entity
//meta refresh the page with the new cursor.
echo '<meta http-equiv="refresh" content="0; url=http://'.$_SERVER['HTTP_HOST'].'/dev/migrate?albumoffset='.rawurlencode($obj_store->getCursor()).'">';
@phpso10
Copy link

phpso10 commented Jul 26, 2016

I could come this far only... but don't know where and how to pass the Cursor variable to FetchPage.

$obj_schema = new GDS\Schema('channels');
$obj_gateway_ns = new GDS\Gateway\ProtoBuf(null, 'bkdatastore');
$obj_store_ns = new \GDS\Store($obj_schema, $obj_gateway_ns);

     $str_gql = "SELECT * FROM channels";
    $obj_request = getBasicFetchRequest();
   $obj_gql_query = $obj_request->mutableGqlQuery();
    $obj_gql_query->setAllowLiteral(TRUE);
     $obj_gql_query->setQueryString($str_gql . " LIMIT @intPageSize OFFSET @startCursor");

    $obj_arg = $obj_gql_query->addNameArg();
    $obj_arg->setName('intPageSize');
    $obj_arg->mutableValue()->setIntegerValue(100);

     $obj_arg_offset = $obj_gql_query->addNameArg();
    $obj_arg_offset->setName('startCursor');
    $obj_arg_offset->setCursor('cur1');

$arr_result = $obj_store_ns->query($str_gql)->fetchPage(5);

 //   $arr_result = $obj_store_ns->fetchPage(5);

     foreach ($arr_result as $obj_ch)
  {
    echo $obj_ch->title, PHP_EOL;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment