Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB integration #1438

Merged
merged 56 commits into from Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ae0f04b
Mongo extension created as blank.
klimov-paul Nov 25, 2013
c61ebcc
Mongo connection advanced.
klimov-paul Nov 25, 2013
c929268
Mongo classes created as blank.
klimov-paul Nov 25, 2013
3b5ee4f
Mongo Command created.
klimov-paul Nov 26, 2013
529af8e
Mongo "Database" and "Collection" classes introduced.
klimov-paul Nov 26, 2013
38df368
Mongo test config updated.
klimov-paul Nov 26, 2013
6eeeb6d
Mongo test config fixed.
klimov-paul Nov 27, 2013
ec2df14
Mongo Connection updated allowing to fetch default database name from…
klimov-paul Nov 27, 2013
4f5f5bb
Mongo Query implemented as draft.
klimov-paul Nov 27, 2013
d42a942
Mongo Command 'update' and 'insertBatch' methods added.
klimov-paul Nov 27, 2013
ee0c9ed
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Nov 28, 2013
1a31b23
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Nov 28, 2013
9da7a80
Mongo query condition composition composed.
klimov-paul Nov 28, 2013
a038449
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Nov 28, 2013
dc3ada6
Mongo query "IN" condition shortcut syntax added.
klimov-paul Nov 28, 2013
37664ff
Mongo Active Record created as draft.
klimov-paul Nov 28, 2013
0f7ded8
Mongo query unit test fixed.
klimov-paul Nov 29, 2013
9c7d2b2
Mongo Active Record and Active Query fixed.
klimov-paul Nov 29, 2013
a39b2d3
Default options setup added to Mongo Collection operations.
klimov-paul Nov 29, 2013
479fbf7
Unit test for Mongo ActiveDataProvider added.
klimov-paul Nov 29, 2013
3fd6d95
Unit test for Mongo Active Relation added.
klimov-paul Nov 29, 2013
27a1c63
Mongo "_id" processing advanced.
klimov-paul Nov 29, 2013
139450d
Mongo condition composition reworked to match original DB interface.
klimov-paul Dec 1, 2013
ac5e174
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Dec 1, 2013
deffc7f
Mongo Active Record reworked to extend BaseActiveRecord.
klimov-paul Dec 1, 2013
1129d82
Mongo Active Relation unit test fixed.
klimov-paul Dec 1, 2013
cddb878
ActiveRelationTrait::getModelKey() updated to work with non scalar keys.
klimov-paul Dec 1, 2013
50a7bfe
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Dec 1, 2013
49a70dc
Mongo aggregation functions added as draft.
klimov-paul Dec 1, 2013
da88e3d
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Dec 1, 2013
0e082c1
Aggregation functions added to Mongo Query.
klimov-paul Dec 2, 2013
c294e03
Unit test for "yii\mongo\Collection::mapReduce()" added.
klimov-paul Dec 2, 2013
469507d
Mongo index manipulation methods added.
klimov-paul Dec 2, 2013
dfefd06
Mongo index related methods fixed.
klimov-paul Dec 2, 2013
96e794b
Merge branch 'master' of github.com:yiisoft/yii2 into mongo
klimov-paul Dec 3, 2013
10bdd6b
Method "execute()" added to Mongo Database.
klimov-paul Dec 3, 2013
a3f5236
Mongo Collection "group" and "mapReduce" functions fixed.
klimov-paul Dec 3, 2013
e3c281f
Mongo Collection "aggregate" method interface refactored.
klimov-paul Dec 3, 2013
1a9d5a1
Mongo Collection "deleteAllIndexes" return result fixed.
klimov-paul Dec 3, 2013
3e744b7
Mongo Collection "findAll" method removed.
klimov-paul Dec 3, 2013
a4224df
Doc comments at Mongo updated.
klimov-paul Dec 3, 2013
aa3a6db
Doc comments at Mongo updated.
klimov-paul Dec 3, 2013
156f7c0
Unit tests for Mongo updated to check nested columns.
klimov-paul Dec 4, 2013
16d857d
Mongo File Collection added.
klimov-paul Dec 4, 2013
f0e6297
Mongo GridFS Query added.
klimov-paul Dec 4, 2013
85a32be
Method "getChunkCollection()" added to Mongo file collection.
klimov-paul Dec 4, 2013
ca608a8
Mongo file Active Record updated.
klimov-paul Dec 4, 2013
77f10ed
Mongo file Active Record saving fixed.
klimov-paul Dec 5, 2013
c0d5c78
Logging and profiling for Mongo File Collection added.
klimov-paul Dec 5, 2013
04fb75b
File retrieve methods added to Mongo File Active Record.
klimov-paul Dec 5, 2013
c783e9f
Mongo File Active Record refactored.
klimov-paul Dec 5, 2013
c542d09
Doc comments at \yii\mongo\file\* updated.
klimov-paul Dec 5, 2013
0fea8a5
Mongo README and composer updated.
klimov-paul Dec 5, 2013
e2f587a
Mongo log tokens improved.
klimov-paul Dec 5, 2013
99b6ae2
Logging and profiling at Mongo improved.
klimov-paul Dec 5, 2013
062e138
Method "\yii\mongo\Collection::fullTextSearch()" added.
klimov-paul Dec 5, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 107 additions & 0 deletions extensions/mongo/ActiveQuery.php
@@ -0,0 +1,107 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\mongo;

use yii\db\ActiveQueryInterface;
use yii\db\ActiveQueryTrait;

/**
* ActiveQuery represents a Mongo query associated with an Active Record class.
*
* ActiveQuery instances are usually created by [[ActiveRecord::find()]].
*
* Because ActiveQuery extends from [[Query]], one can use query methods, such as [[where()]],
* [[orderBy()]] to customize the query options.
*
* ActiveQuery also provides the following additional query options:
*
* - [[with()]]: list of relations that this query should be performed with.
* - [[asArray()]]: whether to return each record as an array.
*
* These options can be configured using methods of the same name. For example:
*
* ~~~
* $customers = Customer::find()->with('orders')->asArray()->all();
* ~~~
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ActiveQuery extends Query implements ActiveQueryInterface
{
use ActiveQueryTrait;

/**
* Executes query and returns all results as an array.
* @param Connection $db the Mongo connection used to execute the query.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* @return array the query results. If the query results in nothing, an empty array will be returned.
*/
public function all($db = null)
{
$cursor = $this->buildCursor($db);
$rows = $this->fetchRows($cursor);
if (!empty($rows)) {
$models = $this->createModels($rows);
if (!empty($this->with)) {
$this->findWith($this->with, $models);
}
return $models;
} else {
return [];
}
}

/**
* Executes query and returns a single row of result.
* @param Connection $db the Mongo connection used to execute the query.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]],
* the query result may be either an array or an ActiveRecord object. Null will be returned
* if the query results in nothing.
*/
public function one($db = null)
{
$row = parent::one($db);
if ($row !== false) {
if ($this->asArray) {
$model = $row;
} else {
/** @var ActiveRecord $class */
$class = $this->modelClass;
$model = $class::create($row);
}
if (!empty($this->with)) {
$models = [$model];
$this->findWith($this->with, $models);
$model = $models[0];
}
return $model;
} else {
return null;
}
}

/**
* Returns the Mongo collection for this query.
* @param Connection $db Mongo connection.
* @return Collection collection instance.
*/
public function getCollection($db = null)
{
/** @var ActiveRecord $modelClass */
$modelClass = $this->modelClass;
if ($db === null) {
$db = $modelClass::getDb();
}
if ($this->from === null) {
$this->from = $modelClass::collectionName();
}
return $db->getCollection($this->from);
}
}