|
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
|
|
|
/** |
|
12
|
|
|
* @inheritdoc |
|
13
|
|
|
*/ |
|
14
|
|
|
public function __construct(Connection $connection, Processor $processor) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->grammar = new Grammar; |
|
17
|
|
|
$this->connection = $connection; |
|
18
|
|
|
$this->processor = $processor; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Insert a new record into the database. |
|
23
|
|
|
* |
|
24
|
|
|
* @param array $values |
|
25
|
|
|
* @return bool |
|
26
|
|
|
*/ |
|
27
|
|
|
public function insert(array $values) |
|
28
|
|
|
{ |
|
29
|
|
|
// Since every insert gets treated like a batch insert, we will make sure the |
|
30
|
|
|
// bindings are structured in a way that is convenient when building these |
|
31
|
|
|
// inserts statements by verifying these elements are actually an array. |
|
32
|
|
|
if (empty($values)) { |
|
33
|
|
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (!is_array(reset($values))) { |
|
37
|
|
|
$values = [$values]; |
|
38
|
|
|
|
|
39
|
|
|
return $this->connection->insert( |
|
40
|
|
|
$this->grammar->compileInsert($this, $values), |
|
41
|
|
|
$this->cleanBindings(Arr::flatten($values, 1)) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// Here, we'll generate the insert queries for every record and send those |
|
46
|
|
|
// for a batch query |
|
47
|
|
|
else { |
|
48
|
|
|
$queries = []; |
|
49
|
|
|
$bindings = []; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($values as $key => $value) { |
|
52
|
|
|
ksort($value); |
|
53
|
|
|
|
|
54
|
|
|
$queries[] = $this->grammar->compileInsert($this, $value); |
|
55
|
|
|
$bindings[] = $this->cleanBindings(Arr::flatten($value, 1)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->connection->insertBulk($queries, $bindings); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
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.