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 26, 2018
1 parent 0e07129 commit 696ff86
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,86 @@ public static function instance()
}


/**
* @param CosmosDbDatabase $connection
* @return $this
*/
public function setConnection(CosmosDbDatabase $connection)
{
$this->connection = $connection;
return $this;
}


/**
* @param $collection
* @return $this
*/
public function collection($collection)
{
$this->collection = $collection;
return $this;
}


/**
* @param $fields
* @return $this
*/
public function select($fields)
{
$this->fields = $fields;
return $this;
}


/**
* @param $join
* @return $this
*/
public function join($join)
{
$this->join = $join;
return $this;
}


/**
* @param $where
* @return $this
*/
public function where($where)
{
$this->where = $where;
return $this;
}


/**
* @param $order
* @return $this
*/
public function order($order)
{
$this->order = $order;
return $this;
}


/**
* @param $limit
* @return $this
*/
public function limit($limit)
{
$this->limit = $limit;
return $this;
}


/**
* @return $this
*/
public function findAll()
{
$this->response = null;
Expand All @@ -97,6 +128,9 @@ public function findAll()
}


/**
* @return $this
*/
public function find()
{
$this->response = null;
Expand All @@ -109,18 +143,9 @@ public function find()
}


public function getValue($fieldName)
{
$this->response = null;
$this->multipleResults = false;

$this->limit = 1;
$this->response = $this->find();

return $this;
}


/**
* @return $this
*/
public function delete()
{
$this->response = null;
Expand All @@ -137,6 +162,9 @@ public function delete()
}


/**
* @return $this
*/
public function deleteAll()
{
$this->response = null;
Expand All @@ -153,12 +181,18 @@ public function deleteAll()
}


/**
* @return string
*/
public function toJson()
{
return $this->response;
}


/**
* @return mixed
*/
public function toObject()
{
$res = json_decode($this->response);
Expand All @@ -170,6 +204,9 @@ public function toObject()
}


/**
* @return array|mixed
*/
public function toArray()
{
$res = json_decode($this->response);
Expand All @@ -178,4 +215,17 @@ public function toArray()
return $this->multipleResults == true && count($docs) > 0 ? $docs : $docs[0];
}


/**
* @param $fieldName
* @param null $default
* @return mixed
*/
public function getValue($fieldName, $default = null)
{
$obj = $this->toObject();

return isset($obj->{$fieldName}) ? $obj->{$fieldName} : $default;
}

}

0 comments on commit 696ff86

Please sign in to comment.