-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathPostgresSelectQuery.php
More file actions
57 lines (46 loc) · 1.39 KB
/
PostgresSelectQuery.php
File metadata and controls
57 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* This file is part of Cycle ORM package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cycle\Database\Driver\Postgres\Query;
use Cycle\Database\Query\Enum\LockMode;
use Cycle\Database\Query\Enum\LockBehavior;
use Cycle\Database\Driver\Postgres\Query\Traits\WhereJsonTrait;
use Cycle\Database\Injection\FragmentInterface;
use Cycle\Database\Query\SelectQuery;
class PostgresSelectQuery extends SelectQuery
{
use WhereJsonTrait;
/**
* Apply distinct ON to the query.
*/
public function distinctOn(FragmentInterface|string $distinctOn): SelectQuery
{
$this->distinct = ['on' => $distinctOn];
return $this;
}
public function forShare(
LockBehavior $behavior = LockBehavior::Wait,
bool $keyOnly = false,
): self {
$this->forUpdate = [
'behavior' => $behavior,
'mode' => $keyOnly === true ? LockMode::KeyShare : LockMode::Share,
];
return $this;
}
public function forUpdate(
LockBehavior $behavior = LockBehavior::Wait,
bool $noKey = false,
): self {
$this->forUpdate = [
'behavior' => $behavior,
'mode' => $noKey === true ? LockMode::NoKeyUpdate : LockMode::Update,
];
return $this;
}
}