ScanQueryTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
  5. use YdbPlatform\Ydb\Enums\ScanQueryMode;
  6. use YdbPlatform\Ydb\Ydb;
  7. use YdbPlatform\Ydb\YdbTable;
  8. class ScanQueryTest extends TestCase
  9. {
  10. function testScanQuery()
  11. {
  12. $config = [
  13. // Database path
  14. 'database' => '/local',
  15. // Database endpoint
  16. 'endpoint' => 'localhost:2136',
  17. // Auto discovery (dedicated server only)
  18. 'discovery' => true,
  19. // IAM config
  20. 'iam_config' => [
  21. 'insecure' => true,
  22. ],
  23. 'credentials' => new AnonymousAuthentication()
  24. ];
  25. $ydb = new Ydb($config, new \YdbPlatform\Ydb\Logger\SimpleStdLogger(7));
  26. $table = $ydb->table();
  27. $table->retrySession(function (\YdbPlatform\Ydb\Session $session){
  28. $session->createTable(
  29. 'scan_table',
  30. YdbTable::make()
  31. ->addColumn('id', 'UINT64')
  32. ->primaryKey('id')
  33. );
  34. }, true);
  35. $yql = 'SELECT id
  36. FROM scan_table
  37. WHERE id = 1;';
  38. $scanWithOutMode = $table->scanQuery($yql);
  39. $scanWithExplainMode = $table->scanQuery($yql, [], ScanQueryMode::MODE_EXPLAIN);
  40. $scanWithExecMode = $table->scanQuery($yql, [], ScanQueryMode::MODE_EXEC);
  41. // These `foreach` needs for requests
  42. foreach ($scanWithOutMode as $value){}
  43. foreach ($scanWithExplainMode as $value){}
  44. foreach ($scanWithExecMode as $value){}
  45. self::expectExceptionMessage("Not implemented");
  46. $scanWithParams = $table->scanQuery($yql, ["value"=>"some"]);
  47. foreach ($scanWithParams as $value){}
  48. }
  49. }