Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit 0992099

Browse files
committed
"update" example in readme
1 parent 84cbd1f commit 0992099

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ echo $mainQuery->get();
169169
*/
170170
```
171171

172-
DATA MODIFICATIONS
173-
================================
172+
### Data Modification ###
174173

175174
* Insert
176175

@@ -201,10 +200,40 @@ echo $mainQuery->get();
201200
*/
202201
```
203202

203+
* Update
204204

205-
* Configuration
206-
* Dependencies
205+
```php
206+
207+
$data = array(
208+
"name" => "Paul",
209+
"age" => 21
210+
)
207211

212+
$query = AqlUpdate::query('u', $data, 'users');
213+
214+
echo $mainQuery->get();
215+
216+
/* Generate this string:
217+
UPDATE {"name": "Paul", "age": 21} IN users
218+
*/
219+
220+
//with filters
221+
$data = array(
222+
'status' => "inactive"
223+
);
224+
225+
$aql = AqlGen::query('u', 'users')
226+
->filter('u.status == 0')
227+
->update($data);
228+
229+
echo $mainQuery->get();
230+
231+
/* Generate this string:
232+
FOR u IN users
233+
FILTER u.status == 0
234+
UPDATE u IN users
235+
*/
236+
```
208237

209238
### Contribution guidelines ###
210239

tarsys/AqlGen/AqlGen.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,42 @@ public function setReturn($return)
304304
return $this;
305305
}
306306

307+
/**
308+
* @param $document
309+
* @param $collection
310+
* @return $this
311+
*/
307312
public function insert($document, $collection)
308313
{
309314
$this->changeOperation = new AqlInsert($document, $collection);
310315
return $this;
311316
}
312317

313-
public function update($document, array $changedAttributes, $collection)
318+
/**
319+
* @param array $changedAttributes
320+
* @param null $document
321+
* @param null $collection
322+
* @return $this
323+
*/
324+
public function update(array $changedAttributes, $document = null, $collection = null)
314325
{
326+
if (is_null($document)) {
327+
$document = $this->document;
328+
}
329+
330+
if (is_null($collection)) {
331+
$collection = $this->collection;
332+
}
315333
$this->changeOperation = new AqlUpdate($document, $changedAttributes, $collection);
316334
return $this;
317335
}
318336

337+
/**
338+
* @param $document
339+
* @param null $collection
340+
* @param array|null $options
341+
* @return $this
342+
*/
319343
public function replace($document, $collection = null, array $options = null)
320344
{
321345
if (is_null($collection)) {
@@ -326,6 +350,11 @@ public function replace($document, $collection = null, array $options = null)
326350
return $this;
327351
}
328352

353+
/**
354+
* @param null $document
355+
* @param null $collection
356+
* @return $this
357+
*/
329358
public function remove($document = null, $collection = null)
330359
{
331360
if (is_null($document)) {

tests/tarsys/AqlGen/AqlGenTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ public function testUpdateOperation()
254254

255255
$aql = AqlGen::query('u', 'users')
256256
->filter('u.status == 0')
257-
->update('u', $data, 'users');
257+
->update($data);
258258

259259
$this->assertEquals("FOR u IN users\n\tFILTER u.status == 0\nUPDATE u WITH {\"status\":\"inactive\"} IN users ", $aql->get());
260260

261261
//with no data
262262
$data = array();
263263
$aql = AqlGen::query('u', 'users')
264-
->update('u', $data, 'users');
264+
->update($data, 'u', 'users');
265265

266266
$this->assertEquals("FOR u IN users\nUPDATE u WITH {} IN users ", $aql->get());
267267
}

0 commit comments

Comments
 (0)