Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
86f22ab3
Commit
86f22ab3
authored
Jul 29, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding raw wheres
parent
23bc58de
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
README.md
README.md
+6
-0
Builder.php
src/Jenssegers/Mongodb/Builder.php
+6
-1
ModelQueryTest.php
tests/ModelQueryTest.php
+14
-0
No files found.
README.md
View file @
86f22ab3
...
@@ -176,6 +176,12 @@ You may also specify additional columns to update:
...
@@ -176,6 +176,12 @@ You may also specify additional columns to update:
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
**Raw Expressions**
These expressions will be injected directly into the query.
User::whereRaw(array('age' => array('$gt' => 30, '$lt' => 40)))->get();
**Query Caching**
**Query Caching**
You may easily cache the results of a query using the remember method:
You may easily cache the results of a query using the remember method:
...
...
src/Jenssegers/Mongodb/Builder.php
View file @
86f22ab3
...
@@ -532,7 +532,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -532,7 +532,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
return
$this
->
compileWhereBasic
(
$where
);
return
$this
->
compileWhereBasic
(
$where
);
}
}
private
function
compileWhere
b
etween
(
$where
)
private
function
compileWhere
B
etween
(
$where
)
{
{
extract
(
$where
);
extract
(
$where
);
...
@@ -543,4 +543,9 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -543,4 +543,9 @@ class Builder extends \Illuminate\Database\Query\Builder {
);
);
}
}
private
function
compileWhereRaw
(
$where
)
{
return
$where
[
'sql'
];
}
}
}
\ No newline at end of file
tests/ModelQueryTest.php
View file @
86f22ab3
...
@@ -322,4 +322,18 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase {
...
@@ -322,4 +322,18 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase {
$this
->
assertTrue
(
is_string
(
$id
));
$this
->
assertTrue
(
is_string
(
$id
));
}
}
public
function
testRaw
()
{
$where
=
array
(
'age'
=>
array
(
'$gt'
=>
30
,
'$lt'
=>
40
));
$users
=
User
::
whereRaw
(
$where
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
$where1
=
array
(
'age'
=>
array
(
'$gt'
=>
30
,
'$lte'
=>
35
));
$where2
=
array
(
'age'
=>
array
(
'$gt'
=>
35
,
'$lt'
=>
40
));
$users
=
User
::
whereRaw
(
$where1
)
->
orWhereRaw
(
$where2
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment