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
4992e8fc
Commit
4992e8fc
authored
Apr 01, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding stuff, not tested
parent
459dd836
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
4 deletions
+52
-4
Model.php
src/Jenssegers/Mongodb/Model.php
+22
-1
Query.php
src/Jenssegers/Mongodb/Query.php
+30
-3
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
4992e8fc
...
@@ -20,6 +20,27 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -20,6 +20,27 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/
*/
protected
$primaryKey
=
'_id'
;
protected
$primaryKey
=
'_id'
;
/**
* Convert a DateTime to a storable string.
*
* @param DateTime $value
* @return MongoDate
*/
protected
function
fromDateTime
(
DateTime
$value
)
{
return
new
MongoDate
(
$value
->
getTimestamp
());
}
/**
* Get a fresh timestamp for the model.
*
* @return MongoDate
*/
public
function
freshTimestamp
()
{
return
new
MongoDate
;
}
/**
/**
* Get a new query builder instance for the connection.
* Get a new query builder instance for the connection.
*
*
...
@@ -28,7 +49,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -28,7 +49,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
protected
function
newBaseQueryBuilder
()
protected
function
newBaseQueryBuilder
()
{
{
$connection
=
$this
->
getConnection
();
$connection
=
$this
->
getConnection
();
return
new
QueryBuilder
(
$connection
,
$this
->
collection
);
return
new
QueryBuilder
(
$connection
);
}
}
}
}
\ No newline at end of file
src/Jenssegers/Mongodb/Query.php
View file @
4992e8fc
...
@@ -32,10 +32,9 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -32,10 +32,9 @@ class Query extends \Illuminate\Database\Query\Builder {
* @param Connection $connection
* @param Connection $connection
* @return void
* @return void
*/
*/
public
function
__construct
(
Connection
$connection
,
$collection
)
public
function
__construct
(
Connection
$connection
)
{
{
$this
->
connection
=
$connection
;
$this
->
connection
=
$connection
;
$this
->
collection
=
$connection
->
getCollection
(
$collection
);
}
}
/**
/**
...
@@ -70,7 +69,22 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -70,7 +69,22 @@ class Query extends \Illuminate\Database\Query\Builder {
if
(
in_array
(
'*'
,
$this
->
columns
))
$this
->
columns
=
array
();
if
(
in_array
(
'*'
,
$this
->
columns
))
$this
->
columns
=
array
();
// Get Mongo cursor
// Get Mongo cursor
$cursor
=
$this
->
collection
->
find
(
$this
->
compileWheres
(),
$this
->
columns
);
if
(
$this
->
distinct
)
{
$cursor
=
$this
->
collection
->
distinct
(
$this
->
columns
,
$this
->
compileWheres
());
}
else
if
(
count
(
$this
->
groups
))
{
$options
=
array
();
$options
[
'condition'
]
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
group
(
$this
->
groups
,
array
(),
NULL
,
$options
);
$cursor
=
$result
[
'retval'
];
}
else
{
$cursor
=
$this
->
collection
->
find
(
$this
->
compileWheres
(),
$this
->
columns
);
}
// Apply order
// Apply order
if
(
$this
->
orders
)
if
(
$this
->
orders
)
...
@@ -174,6 +188,19 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -174,6 +188,19 @@ class Query extends \Illuminate\Database\Query\Builder {
return
0
;
return
0
;
}
}
/**
* Set the collection which the query is targeting.
*
* @param string $collection
* @return Builder
*/
public
function
from
(
$collection
)
{
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
return
$this
;
}
/**
/**
* Compile the where array
* Compile the where array
*
*
...
...
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