|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace fuitad\LaravelCassandra\Query; |
|
4
|
|
|
|
|
5
|
|
|
use fuitad\LaravelCassandra\Connection; |
|
6
|
|
|
use Illuminate\Database\Query\Builder as BaseBuilder; |
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
|
|
9
|
|
|
class Builder extends BaseBuilder |
|
10
|
|
|
{ |
|
11
|
|
|
public $allowFiltering = false; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @inheritdoc |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct(Connection $connection, Grammar $grammar = null, Processor $processor = null) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->connection = $connection; |
|
19
|
|
|
$this->grammar = $grammar ?: $connection->getQueryGrammar(); |
|
20
|
|
|
$this->processor = $processor ?: $connection->getPostProcessor(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Support "allow filtering" |
|
25
|
|
|
*/ |
|
26
|
|
|
public function allowFiltering($bool = true) { |
|
27
|
|
|
$this->allowFiltering = (bool) $bool; |
|
28
|
|
|
|
|
29
|
|
|
return $this; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Insert a new record into the database. |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $values |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
|
|
public function insert(array $values) |
|
39
|
|
|
{ |
|
40
|
|
|
// Since every insert gets treated like a batch insert, we will make sure the |
|
41
|
|
|
// bindings are structured in a way that is convenient when building these |
|
42
|
|
|
// inserts statements by verifying these elements are actually an array. |
|
43
|
|
|
if (empty($values)) { |
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!is_array(reset($values))) { |
|
48
|
|
|
$values = [$values]; |
|
49
|
|
|
|
|
50
|
|
|
return $this->connection->insert( |
|
51
|
|
|
$this->grammar->compileInsert($this, $values), |
|
52
|
|
|
$this->cleanBindings(Arr::flatten($values, 1)) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// Here, we'll generate the insert queries for every record and send those |
|
57
|
|
|
// for a batch query |
|
58
|
|
|
else { |
|
59
|
|
|
$queries = []; |
|
60
|
|
|
$bindings = []; |
|
61
|
|
|
|
|
62
|
|
|
foreach ($values as $key => $value) { |
|
63
|
|
|
ksort($value); |
|
64
|
|
|
|
|
65
|
|
|
$queries[] = $this->grammar->compileInsert($this, $value); |
|
66
|
|
|
$bindings[] = $this->cleanBindings(Arr::flatten($value, 1)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->connection->insertBulk($queries, $bindings); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Execute the query as a "select" statement. |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $columns |
|
78
|
|
|
* @return \Illuminate\Support\Collection |
|
79
|
|
|
*/ |
|
80
|
|
|
public function get($columns = ['*']) |
|
81
|
|
|
{ |
|
82
|
|
|
$original = $this->columns; |
|
83
|
|
|
|
|
84
|
|
|
if (is_null($original)) { |
|
85
|
|
|
$this->columns = $columns; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$results = $this->processor->processSelect($this, $this->runSelect()); |
|
89
|
|
|
|
|
90
|
|
|
$collection = []; |
|
91
|
|
|
while (true) { |
|
92
|
|
|
$collection = array_merge($collection, collect($results)->toArray()); |
|
93
|
|
|
if ($results->isLastPage()) { |
|
94
|
|
|
break; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$results = $results->nextPage(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->columns = $original; |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return collect($collection); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.