查询语言.distinct

Testing Is Documentation

tests/Database/Query/DistinctTest.php查询语言.distinct - 图1

函数原型

  1. # Leevel\Database\Condition::distinct
  2. /**
  3. * 创建一个 SELECT DISTINCT 查询.
  4. *
  5. * @return \Leevel\Database\Condition
  6. */
  7. public function distinct(bool $flag = true): self;

Uses

  1. <?php
  2. use Tests\Database\DatabaseTestCase as TestCase;

查询去重

  1. public function testBaseUse(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT DISTINCT `test_query`.* FROM `test_query`",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->distinct()
  17. ->findAll(true)
  18. )
  19. );
  20. }

取消查询去重

  1. public function testCancelDistinct(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query`",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->distinct()
  17. ->distinct(false)
  18. ->findAll(true),
  19. 1
  20. )
  21. );
  22. }