Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bbb53cca05 | ||
|
a14fb0709f | ||
|
df1f06ad80 | ||
![]() |
7a6e6fbada | ||
![]() |
a7abed56d6 | ||
![]() |
1592238e5f | ||
![]() |
bb4fa52274 | ||
![]() |
7288baa959 | ||
![]() |
bf44832914 | ||
![]() |
5faa656ede | ||
![]() |
3355611e20 | ||
![]() |
a4be42cc82 | ||
![]() |
b1f31103eb | ||
![]() |
6c308b92e7 | ||
![]() |
0dd8e7da47 | ||
![]() |
386f28c618 | ||
![]() |
fbed4c8f9a | ||
![]() |
fe5ba29f09 | ||
![]() |
b833a36a9f | ||
![]() |
528aa8d565 | ||
![]() |
858e86bfab | ||
![]() |
183b2c6343 | ||
![]() |
cc0fc40e10 | ||
![]() |
91f93ca8a0 | ||
![]() |
d0649796c5 | ||
![]() |
75b00ccc59 | ||
![]() |
addcb6ee18 | ||
![]() |
24ff4cd697 | ||
![]() |
7d44b5fa7b | ||
![]() |
6ccd02730c | ||
![]() |
9c704db451 | ||
![]() |
2f4c725b51 | ||
![]() |
094e92df66 | ||
![]() |
c4c9b29e88 | ||
![]() |
ed85a8859f | ||
![]() |
f8db82e5b0 | ||
![]() |
fc1ee326ab |
|
@ -1,3 +1 @@
|
|||
composer.phar
|
||||
composer.lock
|
||||
vendor
|
||||
/vendor
|
14
README.RU.md
14
README.RU.md
|
@ -36,11 +36,11 @@ return [
|
|||
'arangodb' => [
|
||||
'class' => '\explosivebit\arangodb\Connection',
|
||||
'connectionOptions' => [
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_DATABASE => "mydatabase",
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
|
||||
//triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_USER => '',
|
||||
//triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_PASSWD => '',
|
||||
ArangoDBClient\ConnectionOptions::OPTION_DATABASE => "mydatabase",
|
||||
ArangoDBClient\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
|
||||
ArangoDBClient\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
|
||||
//ArangoDBClient\ConnectionOptions::OPTION_AUTH_USER => '',
|
||||
//ArangoDBClient\ConnectionOptions::OPTION_AUTH_PASSWD => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -57,7 +57,7 @@ use explosivebit\arangodb\Query;
|
|||
$query = new Query;
|
||||
// compose the query
|
||||
$query->select(['name', 'status'])
|
||||
->from('customer')
|
||||
->collection('customer')
|
||||
->limit(10);
|
||||
// execute the query
|
||||
$rows = $query->all();
|
||||
|
@ -103,7 +103,7 @@ use yii\data\ActiveDataProvider;
|
|||
use explosivebit\arangodb\Query;
|
||||
|
||||
$query = new Query;
|
||||
$query->from('customer')->where(['status' => 2]);
|
||||
$query->collection('customer')->where(['status' => 2]);
|
||||
$provider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'pagination' => [
|
||||
|
|
45
README.md
45
README.md
|
@ -1,3 +1,6 @@
|
|||
[Описание на Русском](https://github.com/explosivebit/yii2-arangodb/blob/master/README.RU.md)
|
||||
|
||||
|
||||
ArangoDb Extension for Yii 2
|
||||
===========================
|
||||
|
||||
|
@ -38,11 +41,11 @@ return [
|
|||
'arangodb' => [
|
||||
'class' => '\explosivebit\arangodb\Connection',
|
||||
'connectionOptions' => [
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_DATABASE => "mydatabase",
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
|
||||
triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
|
||||
//triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_USER => '',
|
||||
//triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_PASSWD => '',
|
||||
ArangoDBClient\ConnectionOptions::OPTION_DATABASE => "mydatabase",
|
||||
ArangoDBClient\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
|
||||
ArangoDBClient\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
|
||||
//ArangoDBClient\ConnectionOptions::OPTION_AUTH_USER => '',
|
||||
//ArangoDBClient\ConnectionOptions::OPTION_AUTH_PASSWD => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -59,7 +62,7 @@ use explosivebit\arangodb\Query;
|
|||
$query = new Query;
|
||||
// compose the query
|
||||
$query->select(['name', 'status'])
|
||||
->from('customer')
|
||||
->collection('customer')
|
||||
->limit(10);
|
||||
// execute the query
|
||||
$rows = $query->all();
|
||||
|
@ -105,7 +108,7 @@ use yii\data\ActiveDataProvider;
|
|||
use explosivebit\arangodb\Query;
|
||||
|
||||
$query = new Query;
|
||||
$query->from('customer')->where(['status' => 2]);
|
||||
$query->collection('customer')->where(['status' => 2]);
|
||||
$provider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'pagination' => [
|
||||
|
@ -155,8 +158,36 @@ yii arangodb-migrate/create create_user_collection
|
|||
# applies ALL new migrations
|
||||
yii arangodb-migrate
|
||||
|
||||
# Apply 1 migration
|
||||
yii arangodb-migrate/up 1
|
||||
|
||||
# reverts the last applied migration
|
||||
yii arangodb-migrate/down
|
||||
|
||||
# Rollback 1 migration
|
||||
yii arangodb-migrate/down 1
|
||||
```
|
||||
|
||||
Once migration created, you can configure the migration:
|
||||
|
||||
When you start the migration as in the example below, you create a normal document collection with the migration name, you need to add an additional parameter `Type => 3` to create the `edge collection`. Example of such a query: `$this-> createCollection ('services', ['Type' => 3] );` If you want to create a document collection, then delete the `'Type' => 3` or replace the number 3 with 2.
|
||||
|
||||
|
||||
```php
|
||||
class m170413_210957_create_services_collection extends \explosivebit\arangodb\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
# When you start the migration, a collection of "services" with the edge type is created
|
||||
$this->createCollection('services',['Type' => 3]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
# When the migration rollback starts, the collection "services"
|
||||
$this->dropCollection('services');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -1,26 +1,45 @@
|
|||
{
|
||||
"name": "explosivebit/yii2-arangodb",
|
||||
"description": "Yii2 arangodb components",
|
||||
"name": "mirzaev/yii2-arangodb",
|
||||
"description": "Library for connecting ArangoDB to Yii2",
|
||||
"keywords": [
|
||||
"Yii2",
|
||||
"ArangoDB"
|
||||
],
|
||||
"type": "yii2-extension",
|
||||
"keywords": ["yii2","arangodb"],
|
||||
"license": "GPL-3.0+",
|
||||
"license": "WTFPL",
|
||||
"homepage": "https://git.mirzaev.sexy/mirzaev/yii2-arangodb",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||
"email": "arsen@mirzaev.sexy",
|
||||
"homepage": "https://mirzaev.sexy",
|
||||
"role": "Programmer"
|
||||
},
|
||||
{
|
||||
"name": "Ilya Rumyantsev",
|
||||
"email": "explosivebit@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Alvian Burhanuddin",
|
||||
"email": "alvianthelfarqy@gmail.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"yiisoft/yii2": "*",
|
||||
"triagens/arangodb": "*"
|
||||
"php": "^8.0.0",
|
||||
"yiisoft/yii2": "2.*",
|
||||
"triagens/arangodb": "~3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"explosivebit\\arangodb\\": ""
|
||||
"mirzaev\\yii2\\arangodb\\": "mirzaev/yii2/arangodb"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2/arangodb/tests"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQueryInterface;
|
||||
|
@ -20,7 +20,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
|||
parent::__construct($config);
|
||||
}
|
||||
|
||||
protected function buildQuery($query = null, $params = [])
|
||||
protected function genQuery($query = null, array $params = [])
|
||||
{
|
||||
if ($this->primaryModel !== null) {
|
||||
// lazy loading
|
||||
|
@ -46,7 +46,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
|||
}
|
||||
}
|
||||
|
||||
return parent::buildQuery($query, $params);
|
||||
return parent::genQuery($query, $params);
|
||||
}
|
||||
|
||||
private function createModels($rows)
|
||||
|
@ -103,17 +103,21 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
|||
public function all($db = null)
|
||||
{
|
||||
$statement = $this->createCommand($db);
|
||||
|
||||
$token = $this->getRawAql($statement);
|
||||
Yii::info($token, 'explosivebit\arangodb\Query::query');
|
||||
|
||||
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
|
||||
|
||||
try {
|
||||
Yii::beginProfile($token, 'explosivebit\arangodb\Query::query');
|
||||
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
|
||||
$cursor = $statement->execute();
|
||||
$rows = $cursor->getAll();
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Query::query');
|
||||
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::query');
|
||||
} catch (\Exception $ex) {
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Query::query');
|
||||
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::query');
|
||||
throw new \Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
|
||||
}
|
||||
|
||||
if (!empty($rows)) {
|
||||
$models = $this->createModels($rows);
|
||||
if (!empty($this->with)) {
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
@ -102,13 +102,12 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
* // FOR customer IN customer FILTER customer.age>30 RETURN customer
|
||||
* $customers = Customer::find()->where('age>30')->all();
|
||||
*
|
||||
* @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
|
||||
*/
|
||||
public static function find()
|
||||
public static function find(): ActiveQuery
|
||||
{
|
||||
/** @var ActiveQuery $query */
|
||||
$query = \Yii::createObject(ActiveQuery::className(), [get_called_class()]);
|
||||
$query->from(static::collectionName())->select(static::collectionName());
|
||||
$query = Yii::createObject(ActiveQuery::class, [get_called_class()]);
|
||||
$query->in(static::collectionName())->select(static::collectionName());
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -123,6 +122,14 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
$row = $row->getAll();
|
||||
}
|
||||
|
||||
if (!is_iterable($row)) {
|
||||
// Если нельзя обработать полученные данные
|
||||
// Например, если прочитан NULL, то далее будет ошибка при обработке в foreach
|
||||
|
||||
// Реинициализация
|
||||
$row = [];
|
||||
}
|
||||
|
||||
parent::populateRecord($record, $row);
|
||||
}
|
||||
|
||||
|
@ -163,6 +170,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
if ($runValidation && !$this->validate($attributes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->insertInternal($attributes, $options);
|
||||
|
||||
return $result;
|
||||
|
@ -182,7 +190,9 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
}
|
||||
|
||||
$newId = static::getDb()->getDocumentHandler()->save(static::collectionName(), $values);
|
||||
|
||||
static::populateRecord($this, static::getDb()->getDocument(static::collectionName(), $newId));
|
||||
|
||||
$this->setIsNewRecord(false);
|
||||
|
||||
$changedAttributes = array_fill_keys(array_keys($values), null);
|
||||
|
@ -210,8 +220,11 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
$this->afterSave(false, $values);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$condition = $this->getOldPrimaryKey(true);
|
||||
|
||||
$lock = $this->optimisticLock();
|
||||
|
||||
if ($lock !== null) {
|
||||
if (!isset($values[$lock])) {
|
||||
$values[$lock] = $this->$lock + 1;
|
||||
|
@ -223,13 +236,18 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
$this->setAttribute($key, $attribute);
|
||||
}
|
||||
|
||||
$rows = (new Query())->options($options)->update(
|
||||
static::collectionName(),
|
||||
$values,
|
||||
[
|
||||
'_key' => $this->getOldAttribute('_key'),
|
||||
]
|
||||
);
|
||||
$rows = (new Query())
|
||||
->options($options)
|
||||
->in(static::collectionName())
|
||||
->where(['_key' => $this->getOldAttribute('_key')])
|
||||
->update(
|
||||
array_merge(
|
||||
$values,
|
||||
[
|
||||
'_key' => $this->getOldAttribute('_key'),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
if ($lock !== null && !$rows) {
|
||||
throw new StaleObjectException('The object being updated is outdated.');
|
||||
|
@ -251,7 +269,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
*/
|
||||
public static function getDb()
|
||||
{
|
||||
return \Yii::$app->get('arangodb');
|
||||
return Yii::$app->get('arangodb');
|
||||
}
|
||||
|
||||
protected static function findByCondition($condition)
|
||||
|
@ -291,7 +309,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
*/
|
||||
public static function updateAll($attributes, $condition = [], $options = [])
|
||||
{
|
||||
return (new Query())->options($options)->update(static::collectionName(), $attributes, $condition);
|
||||
return (new Query())->options($options)->in(static::collectionName())->update($attributes, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -312,7 +330,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
*/
|
||||
public static function deleteAll($condition = [], $options = [])
|
||||
{
|
||||
return (new Query())->options($options)->remove(static::collectionName(), $condition);
|
||||
return (new Query())->options($options)->in(static::collectionName())->remove($condition);
|
||||
}
|
||||
|
||||
public static function truncate()
|
||||
|
@ -362,6 +380,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
public function delete($options = [])
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if ($this->beforeDelete()) {
|
||||
$result = $this->deleteInternal($options);
|
||||
$this->afterDelete();
|
||||
|
@ -377,14 +396,23 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||
protected function deleteInternal($options = [])
|
||||
{
|
||||
$condition = $this->getOldPrimaryKey(true);
|
||||
|
||||
$lock = $this->optimisticLock();
|
||||
|
||||
if ($lock !== null) {
|
||||
$condition[$lock] = $this->$lock;
|
||||
}
|
||||
$result = (new Query())->options($options)->remove(static::collectionName(), $condition);
|
||||
|
||||
$result = (new Query())
|
||||
->options($options)
|
||||
->in(static::collectionName())
|
||||
->where($condition)
|
||||
->remove();
|
||||
|
||||
if ($lock !== null && !$result) {
|
||||
throw new StaleObjectException('The object being deleted is outdated.');
|
||||
}
|
||||
|
||||
$this->setOldAttributes(null);
|
||||
|
||||
return $result;
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* User: evgen-d
|
||||
* Date: 08.10.14
|
||||
* Time: 16:00
|
||||
*/
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use yii\base\Object;
|
||||
use yii\base\BaseObject;
|
||||
|
||||
class AqlExpression extends Object
|
||||
class AqlExpression extends BaseObject
|
||||
{
|
||||
/**
|
||||
* @var string the AQL expression represented by this object
|
||||
|
@ -37,4 +32,3 @@ class AqlExpression extends Object
|
|||
return $this->expression;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use ArangoDBClient\EdgeHandler;
|
||||
use ArangoDBClient\Export;
|
||||
use ArangoDBClient\GraphHandler;
|
||||
use Yii;
|
||||
use triagens\ArangoDb\CollectionHandler;
|
||||
use triagens\ArangoDb\ConnectionOptions;
|
||||
use triagens\ArangoDb\Document;
|
||||
use triagens\ArangoDb\DocumentHandler;
|
||||
use triagens\ArangoDb\Statement;
|
||||
use triagens\ArangoDb\UpdatePolicy;
|
||||
use ArangoDBClient\CollectionHandler;
|
||||
use ArangoDBClient\ConnectionOptions;
|
||||
use ArangoDBClient\Document;
|
||||
use ArangoDBClient\DocumentHandler;
|
||||
use ArangoDBClient\Statement;
|
||||
use ArangoDBClient\UpdatePolicy;
|
||||
|
||||
use yii\base\Object;
|
||||
use yii\base\BaseObject;
|
||||
|
||||
class Connection extends Object
|
||||
class Connection extends BaseObject
|
||||
{
|
||||
private $connection = null;
|
||||
|
||||
|
@ -42,6 +45,10 @@ class Connection extends Object
|
|||
private $collectionHandler = null;
|
||||
/** @var null|DocumentHandler $documentHandler */
|
||||
private $documentHandler = null;
|
||||
/** @var null|EdgeHandler $documentHandler */
|
||||
private $edgeHandler = null;
|
||||
/** @var null|EdgeHandler $graphHandler */
|
||||
private $graphHandler = null;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
@ -49,18 +56,28 @@ class Connection extends Object
|
|||
|
||||
$token = 'Opening ArangoDB connection: ' . $this->connectionOptions[ConnectionOptions::OPTION_ENDPOINT];
|
||||
try {
|
||||
Yii::info($token, 'explosivebit\arangodb\Connection::open');
|
||||
Yii::beginProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
$this->connection = new \triagens\ArangoDb\Connection($this->connectionOptions);
|
||||
Yii::info($token, 'mirzaev\yii2\arangodb\Connection::open');
|
||||
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Connection::open');
|
||||
$this->connection = new \ArangoDBClient\Connection($this->connectionOptions);
|
||||
$this->collectionHandler = new CollectionHandler($this->connection);
|
||||
$this->documentHandler = new DocumentHandler($this->connection);
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
$this->documentHandler = new DocumentHandler($this->connection);
|
||||
$this->edgeHandler = new EdgeHandler($this->connection);
|
||||
$this->graphHandler = new GraphHandler($this->connection);
|
||||
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Connection::open');
|
||||
} catch (\Exception $ex) {
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
throw new \Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
|
||||
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Connection::open');
|
||||
throw new \Exception($ex->getMessage(), (int)$ex->getCode(), $ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EdgeHandler|null
|
||||
*/
|
||||
public function getGraphHandler(): EdgeHandler
|
||||
{
|
||||
return $this->graphHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|CollectionHandler
|
||||
*/
|
||||
|
@ -86,6 +103,14 @@ class Connection extends Object
|
|||
return $this->documentHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|EdgeHandler
|
||||
*/
|
||||
public function getEdgeHandler()
|
||||
{
|
||||
return $this->edgeHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collectionId
|
||||
* @param $documentId
|
||||
|
@ -104,4 +129,12 @@ class Connection extends Object
|
|||
{
|
||||
return new Statement($this->connection, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @return Export
|
||||
*/
|
||||
public function getExport($options = []) {
|
||||
return new Export($this->connection, $options);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
class Exception extends \yii\base\Exception
|
||||
{
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use yii\base\Component;
|
||||
use yii\db\MigrationInterface;
|
||||
|
@ -22,7 +22,8 @@ abstract class Migration extends Component implements MigrationInterface
|
|||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->db = Instance::ensure($this->db, Connection::className());
|
||||
|
||||
$this->db = Instance::ensure($this->db, Connection::class);
|
||||
}
|
||||
|
||||
public function execute($aql, $bindValues = [], $params = [])
|
||||
|
@ -86,4 +87,6 @@ abstract class Migration extends Component implements MigrationInterface
|
|||
$this->db->getCollectionHandler()->truncate($collection);
|
||||
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
|
||||
}
|
||||
|
||||
// Разработать создание графов и представлений
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* User: evgen-d
|
||||
* Date: 08.10.14
|
||||
* Time: 16:04
|
||||
*/
|
||||
|
||||
namespace explosivebit\arangodb;
|
||||
namespace mirzaev\yii2\arangodb;
|
||||
|
||||
use yii\base\Arrayable;
|
||||
|
||||
|
@ -56,4 +51,3 @@ class Serializer
|
|||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb\console\controllers;
|
||||
namespace mirzaev\yii2\arangodb\console\controllers;
|
||||
|
||||
use explosivebit\arangodb\Connection;
|
||||
use explosivebit\arangodb\Exception;
|
||||
use explosivebit\arangodb\Migration;
|
||||
use explosivebit\arangodb\Query;
|
||||
use mirzaev\yii2\arangodb\Connection;
|
||||
use mirzaev\yii2\arangodb\Exception;
|
||||
use mirzaev\yii2\arangodb\Migration;
|
||||
use mirzaev\yii2\arangodb\Query;
|
||||
|
||||
use yii;
|
||||
use yii\console\controllers\BaseMigrateController;
|
||||
|
@ -17,15 +17,18 @@ class MigrateController extends BaseMigrateController
|
|||
* @var string the name of the collection for keeping applied migration information.
|
||||
*/
|
||||
public $migrationCollection = 'migration';
|
||||
|
||||
/**
|
||||
* @var string the directory storing the migration classes. This can be either
|
||||
* a path alias or a directory.
|
||||
*/
|
||||
public $migrationPath = '@app/migrations/arangodb';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $templateFile = '@explosivebit/arangodb/views/migration.php';
|
||||
public $templateFile = '@mirzaev/yii2/arangodb/views/migration.php';
|
||||
|
||||
/**
|
||||
* @var Connection|string the DB connection object or the application
|
||||
* component ID of the DB connection.
|
||||
|
@ -55,7 +58,7 @@ class MigrateController extends BaseMigrateController
|
|||
if (parent::beforeAction($action)) {
|
||||
if ($action->id !== 'create') {
|
||||
if (is_string($this->db)) {
|
||||
$this->db = \Yii::$app->get($this->db);
|
||||
$this->db = yii::$app->get($this->db);
|
||||
}
|
||||
if (!$this->db instanceof Connection) {
|
||||
throw new Exception("The 'db' option must refer to the application component ID of a ArangoDB connection.");
|
||||
|
@ -104,7 +107,7 @@ class MigrateController extends BaseMigrateController
|
|||
{
|
||||
$query = new Query;
|
||||
$rows = $query->select(['version' => 'version', 'apply_time' => 'apply_time'])
|
||||
->from($this->migrationCollection)
|
||||
->collection($this->migrationCollection)
|
||||
->orderBy('version DESC')
|
||||
->limit($limit)
|
||||
->all($this->db);
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb\panels\arangodb;
|
||||
namespace mirzaev\yii2\arangodb\panels\arangodb;
|
||||
|
||||
use explosivebit\arangodb\panels\arangodb\models\ArangoDb;
|
||||
use Yii;
|
||||
use mirzaev\yii2\arangodb\panels\arangodb\models\ArangoDb;
|
||||
use yii;
|
||||
use yii\debug\Panel;
|
||||
use yii\log\Logger;
|
||||
|
||||
|
@ -31,11 +31,11 @@ class ArangoDbPanel extends Panel
|
|||
$target->messages,
|
||||
Logger::LEVEL_PROFILE,
|
||||
[
|
||||
'explosivebit\arangodb\Query::query',
|
||||
'explosivebit\arangodb\Query::insert',
|
||||
'explosivebit\arangodb\Query::update',
|
||||
'explosivebit\arangodb\Query::remove',
|
||||
'explosivebit\arangodb\Query::execute',
|
||||
'mirzaev\yii2\arangodb\Query::query',
|
||||
'mirzaev\yii2\arangodb\Query::insert',
|
||||
'mirzaev\yii2\arangodb\Query::update',
|
||||
'mirzaev\yii2\arangodb\Query::remove',
|
||||
'mirzaev\yii2\arangodb\Query::execute',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class ArangoDbPanel extends Panel
|
|||
protected function calculateTimings()
|
||||
{
|
||||
if ($this->_timings === null) {
|
||||
$this->_timings = Yii::getLogger()->calculateTimings($this->data['arango-messages']);
|
||||
$this->_timings = yii::getLogger()->calculateTimings($this->data['arango-messages']);
|
||||
}
|
||||
|
||||
return $this->_timings;
|
||||
|
@ -82,8 +82,8 @@ class ArangoDbPanel extends Panel
|
|||
$queryCount = count($timings);
|
||||
$queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms';
|
||||
|
||||
return \Yii::$app->view->render(
|
||||
'@explosivebit/arangodb/panels/arangodb/views/summary',
|
||||
return \yii::$app->view->render(
|
||||
'@mirzaev/yii2/arangodb/panels/arangodb/views/summary',
|
||||
[
|
||||
'timings' => $this->calculateTimings(),
|
||||
'queryCount' => $queryCount,
|
||||
|
@ -99,9 +99,9 @@ class ArangoDbPanel extends Panel
|
|||
public function getDetail()
|
||||
{
|
||||
$searchModel = new ArangoDb();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), $this->getModels());
|
||||
$dataProvider = $searchModel->search(yii::$app->request->getQueryParams(), $this->getModels());
|
||||
|
||||
return Yii::$app->view->render('@explosivebit/arangodb/panels/arangodb/views/detail', [
|
||||
return yii::$app->view->render('@mirzaev/yii2/arangodb/panels/arangodb/views/detail', [
|
||||
'panel' => $this,
|
||||
'dataProvider' => $dataProvider,
|
||||
'searchModel' => $searchModel,
|
||||
|
@ -136,15 +136,15 @@ class ArangoDbPanel extends Panel
|
|||
|
||||
protected function getQueryType($category) {
|
||||
switch ($category) {
|
||||
case 'explosivebit\arangodb\Query::query' :
|
||||
case 'mirzaev\yii2\arangodb\Query::query' :
|
||||
return 'SELECT';
|
||||
case 'explosivebit\arangodb\Query::insert' :
|
||||
case 'mirzaev\yii2\arangodb\Query::insert' :
|
||||
return 'INSERT';
|
||||
case 'explosivebit\arangodb\Query::update' :
|
||||
case 'mirzaev\yii2\arangodb\Query::update' :
|
||||
return 'UPDATE';
|
||||
case 'explosivebit\arangodb\Query::remove' :
|
||||
case 'mirzaev\yii2\arangodb\Query::remove' :
|
||||
return 'REMOVE';
|
||||
case 'explosivebit\arangodb\Query::execute' :
|
||||
case 'mirzaev\yii2\arangodb\Query::execute' :
|
||||
return 'EXECUTE';
|
||||
default :
|
||||
return '';
|
||||
|
@ -155,4 +155,4 @@ class ArangoDbPanel extends Panel
|
|||
{
|
||||
return ['arango-messages' => $this->getProfileLogs()];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace explosivebit\arangodb\panels\arangodb\models;
|
||||
namespace mirzaev\yii2\arangodb\panels\arangodb\models;
|
||||
|
||||
use yii;
|
||||
use yii\data\ArrayDataProvider;
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* This view is used by console/controllers/MigrateController.php
|
||||
* The following variables are available in this view:
|
||||
*/
|
||||
|
||||
/* @var $className string the new migration class name */
|
||||
|
||||
echo <<<HTML
|
||||
<?php
|
||||
|
||||
use mirzaev\yii2\arangodb\Migration;
|
||||
|
||||
class $className extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
/**
|
||||
* @param string Название коллекции
|
||||
* @param array Тип коллекции (2 - документ, 3 - ребро)
|
||||
*/
|
||||
\$this->createCollection('$className', ['type' => 2]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
\$this->dropCollection('$className');
|
||||
}
|
||||
}
|
||||
HTML;
|
||||
|
||||
?>
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This view is used by console/controllers/MigrateController.php
|
||||
* The following variables are available in this view:
|
||||
*/
|
||||
|
||||
/* @var $className string the new migration class name */
|
||||
echo "<?php\n";
|
||||
?>
|
||||
|
||||
class <?= $className ?> extends \explosivebit\arangodb\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->createCollection('<?= $className ?>',[]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->dropCollection('<?= $className ?>');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue