/
Builder.php
74 lines (62 loc) · 1.85 KB
/
Builder.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace Sunaoka\LaravelPostgres\Query;
/**
* @property \Sunaoka\LaravelPostgres\Query\Grammars\PostgresGrammar $grammar
*/
class Builder extends \Illuminate\Database\Query\Builder
{
/**
* @var array
*/
public $returning = [];
/**
* @param array $columns
* @return $this
*/
public function returning(array $columns = []): self
{
$this->returning = $columns;
return $this;
}
/**
* Update records in the database.
*
* @param array $values
* @return int|array
*/
public function update(array $values)
{
$sql = $this->grammar->compileUpdate($this, $values);
$bindings = $this->cleanBindings(
$this->grammar->prepareBindingsForUpdate($this->bindings, $values)
);
if (empty($this->returning)) {
return $this->connection->update($sql, $bindings);
}
return $this->connection->select($sql, $bindings);
}
/**
* Delete records from the database.
*
* @param mixed $id
* @return int|array
*/
public function delete($id = null)
{
// If an ID is passed to the method, we will set the where clause to check the
// ID to let developers to simply and quickly remove a single row from this
// database without manually specifying the "where" clauses on the query.
if (! is_null($id)) {
$this->where($this->from.'.id', '=', $id);
}
$query = $this->grammar->compileDelete($this);
$bindings = $this->cleanBindings(
$this->grammar->prepareBindingsForDelete($this->bindings)
);
if (empty($this->returning)) {
return $this->connection->delete($query, $bindings);
}
return $this->connection->select($query, $bindings);
}
}