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
a90d8bdc
Commit
a90d8bdc
authored
May 01, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding whereBetween
parent
97fd865d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
15 deletions
+42
-15
README.md
README.md
+4
-0
Query.php
src/Jenssegers/Mongodb/Query.php
+38
-15
No files found.
README.md
View file @
a90d8bdc
...
@@ -76,6 +76,10 @@ Examples
...
@@ -76,6 +76,10 @@ Examples
$users = User::whereIn('age', array(16, 18, 20))->get();
$users = User::whereIn('age', array(16, 18, 20))->get();
**Using Where Between**
$users = User::whereBetween('votes', array(1, 100))->get();
**Where null**
**Where null**
$users = User::whereNull('updated_at')->get();
$users = User::whereNull('updated_at')->get();
...
...
src/Jenssegers/Mongodb/Query.php
View file @
a90d8bdc
...
@@ -210,6 +210,25 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -210,6 +210,25 @@ class Query extends \Illuminate\Database\Query\Builder {
return
$this
;
return
$this
;
}
}
/**
* Add a where between statement to the query.
*
* @param string $column
* @param array $values
* @param string $boolean
* @return \Illuminate\Database\Query\Builder
*/
public
function
whereBetween
(
$column
,
array
$values
,
$boolean
=
'and'
)
{
$type
=
'between'
;
$this
->
wheres
[]
=
compact
(
'column'
,
'type'
,
'boolean'
,
'values'
);
$this
->
bindings
=
array_merge
(
$this
->
bindings
,
$values
);
return
$this
;
}
/**
/**
* Insert a new record into the database.
* Insert a new record into the database.
*
*
...
@@ -312,7 +331,7 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -312,7 +331,7 @@ class Query extends \Illuminate\Database\Query\Builder {
public
function
compileWheres
()
public
function
compileWheres
()
{
{
if
(
!
$this
->
wheres
)
return
array
();
if
(
!
$this
->
wheres
)
return
array
();
$wheres
=
array
();
$wheres
=
array
();
foreach
(
$this
->
wheres
as
$i
=>&
$where
)
foreach
(
$this
->
wheres
as
$i
=>&
$where
)
...
@@ -334,6 +353,12 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -334,6 +353,12 @@ class Query extends \Illuminate\Database\Query\Builder {
$method
=
"compileWhere
{
$where
[
'type'
]
}
"
;
$method
=
"compileWhere
{
$where
[
'type'
]
}
"
;
$compiled
=
$this
->
{
$method
}(
$where
);
$compiled
=
$this
->
{
$method
}(
$where
);
// Check for or
if
(
$where
[
'boolean'
]
==
'or'
)
{
$compiled
=
array
(
'$or'
=>
array
(
$compiled
));
}
// Merge compiled where
// Merge compiled where
$wheres
=
array_merge_recursive
(
$wheres
,
$compiled
);
$wheres
=
array_merge_recursive
(
$wheres
,
$compiled
);
}
}
...
@@ -367,11 +392,6 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -367,11 +392,6 @@ class Query extends \Illuminate\Database\Query\Builder {
$query
=
array
(
$column
=>
array
(
$this
->
conversion
[
$operator
]
=>
$value
));
$query
=
array
(
$column
=>
array
(
$this
->
conversion
[
$operator
]
=>
$value
));
}
}
if
(
$boolean
==
'or'
)
{
return
array
(
'$or'
=>
array
(
$query
));
}
return
$query
;
return
$query
;
}
}
...
@@ -379,15 +399,7 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -379,15 +399,7 @@ class Query extends \Illuminate\Database\Query\Builder {
{
{
extract
(
$where
);
extract
(
$where
);
// Compile subquery
return
$query
->
compileWheres
();
$compiled
=
$query
->
compileWheres
();
if
(
$boolean
==
'or'
)
{
return
array
(
'$or'
=>
array
(
$compiled
));
}
return
$compiled
;
}
}
public
function
compileWhereIn
(
$where
)
public
function
compileWhereIn
(
$where
)
...
@@ -413,6 +425,17 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -413,6 +425,17 @@ class Query extends \Illuminate\Database\Query\Builder {
return
$this
->
compileWhereBasic
(
$where
);
return
$this
->
compileWhereBasic
(
$where
);
}
}
public
function
compileWherebetween
(
$where
)
{
extract
(
$where
);
return
array
(
$column
=>
array
(
'$gte'
=>
$values
[
0
],
'$lte'
=>
$values
[
1
])
);
}
/**
/**
* Get a new instance of the query builder.
* Get a new instance of the query builder.
*
*
...
...
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