Skip to content

Commit

Permalink
Update QueryBuilder.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Chaves authored Sep 28, 2018
1 parent af168c7 commit e31de98
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public function find()

/* insert / update */

/**
* @param $document
* @return $this
*/
public function setDocument($document)
{
if (is_array($document) || is_object($document)) {
Expand All @@ -160,6 +164,11 @@ public function setDocument($document)
}


/**
* @param $document
* @return null
* @throws \Exception
*/
public function save($document)
{
$rid = null;
Expand Down Expand Up @@ -230,6 +239,7 @@ public function toJson()
{
return $this->response;
}

/**
* @return mixed
*/
Expand All @@ -239,17 +249,28 @@ public function toObject()
$docs = $res->Documents ?? [];
if (!is_array($docs) || empty($docs)) return [];

return $this->multipleResults == true ? $docs : $docs[0];
if ($this->multipleResults) {
return $docs;
}

return isset($docs[0]) ? $docs[0] : null;
}

/**
* @return array|mixed
*/
public function toArray()
{
$res = json_decode($this->response);
$docs = $res->Documents ?? [];
return $this->multipleResults == true ? $docs : $docs[0];

if ($this->multipleResults) {
return $docs;
}

return isset($docs[0]) ? $docs[0] : null;
}

/**
* @param $fieldName
* @param null $default
Expand Down

0 comments on commit e31de98

Please sign in to comment.