Commit 9d26ccb9 authored by Jens Segers's avatar Jens Segers

Adding some features

parent d151beff
...@@ -53,6 +53,13 @@ class Query { ...@@ -53,6 +53,13 @@ class Query {
*/ */
public $limit; public $limit;
/**
* The number of records to skip.
*
* @var int
*/
public $offset;
/** /**
* All of the available operators. * All of the available operators.
* *
...@@ -93,6 +100,19 @@ class Query { ...@@ -93,6 +100,19 @@ class Query {
return $this; return $this;
} }
/**
* Set the "offset" value of the query.
*
* @param int $value
* @return \Illuminate\Database\Query\Builder
*/
public function skip($value)
{
$this->offset = $value;
return $this;
}
/** /**
* Add an "order by" clause to the query. * Add an "order by" clause to the query.
* *
...@@ -186,6 +206,12 @@ class Query { ...@@ -186,6 +206,12 @@ class Query {
$cursor->sort($this->orders); $cursor->sort($this->orders);
} }
// Apply offset
if ($this->offset)
{
$cursor->skip($this->offset);
}
// Apply limit // Apply limit
if ($this->limit) if ($this->limit)
{ {
...@@ -196,6 +222,79 @@ class Query { ...@@ -196,6 +222,79 @@ class Query {
return $this->toCollection($cursor); return $this->toCollection($cursor);
} }
/**
* Insert a new document into the database.
*
* @param array $data
* @return mixed
*/
public function insert($data)
{
$result = $this->collection->insert($data);
if(1 == (int) $result['ok'])
{
return $data['_id'];
}
return false;
}
/**
* Save the document. Insert into the database if its not exists.
*
* @param array $data
* @return mixed
*/
public function save($data)
{
$this->collection->save($data);
if(isset($data['_id']))
{
return $data['_id'];
}
return false;
}
/**
* Update a document in the database.
*
* @param array $data
* @return int
*/
public function update(array $data)
{
$update = array('$set' => $data);
$result = $this->collection->update($this->wheres, $update, array('multiple' => true));
if(1 == (int) $result['ok'])
{
return $result['n'];
}
return 0;
}
/**
* Delete a document from the database.
*
* @return int
*/
public function delete()
{
$result = $this->collection->remove($this->wheres);
if(1 == (int) $result['ok'])
{
return $result['n'];
}
return 0;
}
/** /**
* Transform to model collection. * Transform to model collection.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment