Skip to content

Commit

Permalink
added whereNotIn() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Chaves authored Jan 11, 2019
1 parent 5f3438b commit 5e95d27
Showing 1 changed file with 58 additions and 23 deletions.
81 changes: 58 additions & 23 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,19 @@ public function setCollection(CosmosDbCollection $collection)


/**
* @param $fields
* @param string|array $fields
* @return $this
*/
public function select($fields)
{

if (is_array($fields))
$fields = 'c["' . implode('"], c["', $fields) . '"]';

$this->fields = $fields;
return $this;
}
public function select($fields)
{
if (is_array($fields))
$fields = 'c["' . implode('"], c["', $fields) . '"]';
$this->fields = $fields;
return $this;
}

/**
* @param $from
* @param string $from
* @return $this
*/
public function from($from)
Expand All @@ -85,7 +83,7 @@ public function from($from)


/**
* @param $join
* @param string $join
* @return $this
*/
public function join($join)
Expand All @@ -96,7 +94,7 @@ public function join($join)


/**
* @param $where
* @param string $where
* @return $this
*/
public function where($where)
Expand All @@ -107,31 +105,65 @@ public function where($where)
return $this;
}

public function whereStartsWith($field, $value)
/**
* @param string $field
* @param string $value
* @return QueryBuilder
*/
public function whereStartsWith($field, $value)
{
return $this->where("STARTSWITH($field, '{$value}')");
}

public function whereEndsWith($field, $value)
/**
* @param string $field
* @param string $value
* @return QueryBuilder
*/
public function whereEndsWith($field, $value)
{
return $this->where("ENDSWITH($field, '{$value}')");
}

public function whereContains($field, $value)
/**
* @param string $field
* @param string $value
* @return QueryBuilder
*/
public function whereContains($field, $value)
{
return $this->where("CONTAINS($field, '{$value}'");
}

public function whereIn($field, $values)
/**
* @param string $field
* @param array $values
* @return $this|QueryBuilder
*/
public function whereIn($field, $values)
{
if (is_array($values))
$values = implode("', '", $values);
if (!is_array($values) || empty($values)) return $this;
if (is_array($values)) $values = implode("', '", $values);

return $this->where("$field IN('{$values}')");
}

/**
* @param string $field
* @param array $values
* @return $this|QueryBuilder
*/
public function whereNotIn($field, $values)
{
if (!is_array($values) || empty($values)) return $this;
if (is_array($values)) $values = implode("', '", $values);

return $this->where("$field NOT IN('{$values}')");
}


/**
* @param $order
* @param string $order
* @return $this
*/
public function order($order)
Expand All @@ -142,12 +174,12 @@ public function order($order)


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

Expand Down Expand Up @@ -232,7 +264,10 @@ public function setPartitionKey($fieldName)
return $this;
}

public function getPartitionKey()
/**
* @return null
*/
public function getPartitionKey()
{
return $this->partitionKey;
}
Expand Down

0 comments on commit 5e95d27

Please sign in to comment.