@@ 75-101 (lines=27) @@ | ||
72 | * |
|
73 | * @return bool |
|
74 | */ |
|
75 | public function insert(array $values) |
|
76 | { |
|
77 | if (empty($values)) { |
|
78 | return true; |
|
79 | } |
|
80 | ||
81 | if (!is_array(reset($values))) { |
|
82 | $values = [$values]; |
|
83 | } else { |
|
84 | foreach ($values as $key => $value) { |
|
85 | ksort($value); |
|
86 | $values[$key] = $value; |
|
87 | } |
|
88 | } |
|
89 | ||
90 | $bindings = []; |
|
91 | ||
92 | foreach ($values as $record) { |
|
93 | foreach ($record as $key => $value) { |
|
94 | $bindings[$key] = $value; |
|
95 | } |
|
96 | } |
|
97 | ||
98 | $sql = $this->grammar->compileInsert($this, $values); |
|
99 | ||
100 | return $this->connection->insert($sql, $bindings); |
|
101 | } |
|
102 | ||
103 | /** |
|
104 | * supported N1QL upsert query. |
|
@@ 110-136 (lines=27) @@ | ||
107 | * |
|
108 | * @return bool|mixed |
|
109 | */ |
|
110 | public function upsert(array $values) |
|
111 | { |
|
112 | if (empty($values)) { |
|
113 | return true; |
|
114 | } |
|
115 | ||
116 | if (!is_array(reset($values))) { |
|
117 | $values = [$values]; |
|
118 | } else { |
|
119 | foreach ($values as $key => $value) { |
|
120 | ksort($value); |
|
121 | $values[$key] = $value; |
|
122 | } |
|
123 | } |
|
124 | ||
125 | $bindings = []; |
|
126 | ||
127 | foreach ($values as $record) { |
|
128 | foreach ($record as $key => $value) { |
|
129 | $bindings[$key] = $value; |
|
130 | } |
|
131 | } |
|
132 | ||
133 | $sql = $this->grammar->compileUpsert($this, $values); |
|
134 | ||
135 | return $this->connection->upsert($sql, $bindings); |
|
136 | } |
|
137 | } |
|
138 |