Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6c308b92e7 | ||
![]() |
0dd8e7da47 | ||
![]() |
386f28c618 | ||
![]() |
fbed4c8f9a | ||
![]() |
fe5ba29f09 | ||
![]() |
b833a36a9f | ||
![]() |
528aa8d565 | ||
![]() |
858e86bfab | ||
![]() |
183b2c6343 | ||
![]() |
cc0fc40e10 | ||
![]() |
91f93ca8a0 | ||
![]() |
d0649796c5 | ||
![]() |
75b00ccc59 | ||
![]() |
addcb6ee18 | ||
![]() |
24ff4cd697 | ||
![]() |
7d44b5fa7b | ||
![]() |
6ccd02730c | ||
![]() |
9c704db451 | ||
![]() |
2f4c725b51 | ||
![]() |
094e92df66 | ||
![]() |
c4c9b29e88 | ||
![]() |
ed85a8859f | ||
![]() |
f8db82e5b0 | ||
![]() |
fc1ee326ab | ||
![]() |
99d42076a6 |
@@ -1,26 +1,36 @@
|
||||
{
|
||||
"name": "explosivebit/yii2-arangodb",
|
||||
"description": "Yii2 arangodb components",
|
||||
"type": "yii2-extension",
|
||||
"keywords": ["yii2","arangodb"],
|
||||
"license": "GPL-3.0+",
|
||||
"name": "mirzaev/yii2-arangodb",
|
||||
"description": "Library for connecting ArangoDB-PHP to Yii2",
|
||||
"type": "library",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"homepage": "https://git.hood.su/mirzaev/yii2/arangodb",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ilya Rumyantsev",
|
||||
"email": "explosivebit@gmail.com"
|
||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||
"email": "red@hood.su",
|
||||
"homepage": "https://hood.su/mirzaev",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"homepage": "https://github.com/explosivebit/yii2-arangodb",
|
||||
"role": "Old fork (abandoned)"
|
||||
},
|
||||
{
|
||||
"homepage": "https://github.com/DevGroup-ru/yii2-arangodb",
|
||||
"role": "Original repository (abandoned)"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"yiisoft/yii2": "*",
|
||||
"triagens/arangodb": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "*"
|
||||
"php": "^8.0.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"explosivebit\\arangodb\\": ""
|
||||
"mirzaev\\yii2\\arangodb\\": "mirzaev/yii2-arangodb"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2-arangodb/tests"
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,17 +2,20 @@
|
||||
|
||||
namespace explosivebit\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()
|
||||
{
|
||||
@@ -51,9 +58,11 @@ class Connection extends Object
|
||||
try {
|
||||
Yii::info($token, 'explosivebit\arangodb\Connection::open');
|
||||
Yii::beginProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
$this->connection = new \triagens\ArangoDb\Connection($this->connectionOptions);
|
||||
$this->connection = new \ArangoDBClient\Connection($this->connectionOptions);
|
||||
$this->collectionHandler = new CollectionHandler($this->connection);
|
||||
$this->documentHandler = new DocumentHandler($this->connection);
|
||||
$this->edgeHandler = new EdgeHandler($this->connection);
|
||||
$this->graphHandler = new GraphHandler($this->connection);
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
} catch (\Exception $ex) {
|
||||
Yii::endProfile($token, 'explosivebit\arangodb\Connection::open');
|
||||
@@ -61,6 +70,14 @@ class Connection extends Object
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
@@ -3,8 +3,8 @@
|
||||
namespace explosivebit\arangodb;
|
||||
|
||||
use Yii;
|
||||
use triagens\ArangoDb\Document;
|
||||
use triagens\ArangoDb\Statement;
|
||||
use ArangoDBClient\Document;
|
||||
use ArangoDBClient\Statement;
|
||||
use yii\base\Component;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\NotSupportedException;
|
207
mirzaev/yii2-arangodb/README.RU.md
Normal file
207
mirzaev/yii2-arangodb/README.RU.md
Normal file
@@ -0,0 +1,207 @@
|
||||
Коннектор ArangoDb PHP для Yii 2
|
||||
===========================
|
||||
|
||||
Это расширение [ArangoDB](http://www.arangodb.org/) обеспечивает интеграцию в фрэймворком Yii2.
|
||||
|
||||
|
||||
Установка
|
||||
------------
|
||||
|
||||
Это расширение требует [ArangoDB PHP Extension](https://github.com/triAGENS/ArangoDB-PHP)
|
||||
|
||||
Предпочтительный способ установки с помощью [composer](http://getcomposer.org/download/).
|
||||
|
||||
Или запустить команду
|
||||
|
||||
```
|
||||
php composer.phar require --prefer-dist explosivebit/yii2-arangodb "*"
|
||||
```
|
||||
|
||||
или добавить в файл "composer.json"
|
||||
|
||||
```
|
||||
"explosivebit/yii2-arangodb": "*"
|
||||
```
|
||||
|
||||
|
||||
Использование
|
||||
-------------
|
||||
|
||||
Чтобы использовать это расширение, просто добавьте следующий код в конфигурацию вашего приложения:
|
||||
|
||||
```php
|
||||
return [
|
||||
//....
|
||||
'components' => [
|
||||
'arangodb' => [
|
||||
'class' => '\explosivebit\arangodb\Connection',
|
||||
'connectionOptions' => [
|
||||
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 => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
С помощью экземпляра подключения вы можете обращаться к базам данных, коллекциям и документам.
|
||||
|
||||
Для выполнения запросов «search» вы должны использовать следующий класс `\explosivebit\arangodb\Query`:
|
||||
|
||||
```php
|
||||
use explosivebit\arangodb\Query;
|
||||
|
||||
$query = new Query;
|
||||
// compose the query
|
||||
$query->select(['name', 'status'])
|
||||
->from('customer')
|
||||
->limit(10);
|
||||
// execute the query
|
||||
$rows = $query->all();
|
||||
```
|
||||
|
||||
|
||||
Использование ActiveRecord ArangoDB
|
||||
------------------------------
|
||||
|
||||
Этот клас обеспечивает аналогичное решение yii2 ActiveRecord, `\yii\db\ActiveRecord`.
|
||||
Чтобы объявить класс ActiveRecord, вам необходимо расширить `\explosivebit\arangodb\ActiveRecord` и
|
||||
реализовать методы `collectionName` и `attributes`:
|
||||
|
||||
```php
|
||||
use explosivebit\arangodb\ActiveRecord;
|
||||
|
||||
class Customer extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @return string the name of the index associated with this ActiveRecord class.
|
||||
*/
|
||||
public static function collectionName()
|
||||
{
|
||||
return 'customer';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array list of attribute names.
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
return ['_key', 'name', 'email', 'address', 'status'];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Примечание: имя первичного ключа ('_key') любой коллекции должно всегда присутствовать и настроено как атрибут.
|
||||
|
||||
Вы можете использовать `\yii\data\ActiveDataProvider` c `\explosivebit\arangodb\Query` а также `\explosivebit\arangodb\ActiveQuery`:
|
||||
|
||||
```php
|
||||
use yii\data\ActiveDataProvider;
|
||||
use explosivebit\arangodb\Query;
|
||||
|
||||
$query = new Query;
|
||||
$query->from('customer')->where(['status' => 2]);
|
||||
$provider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'pagination' => [
|
||||
'pageSize' => 10,
|
||||
]
|
||||
]);
|
||||
$models = $provider->getModels();
|
||||
```
|
||||
|
||||
```php
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\Customer;
|
||||
|
||||
$provider = new ActiveDataProvider([
|
||||
'query' => Customer::find(),
|
||||
'pagination' => [
|
||||
'pageSize' => 10,
|
||||
]
|
||||
]);
|
||||
$models = $provider->getModels();
|
||||
```
|
||||
|
||||
|
||||
Использование миграций
|
||||
----------------
|
||||
|
||||
ArangoDB миграции осуществляются через `explosivebit\arangodb\console\controllers\MigrateController`, который является аналогом стандартных миграций yii2
|
||||
`\yii\console\controllers\MigrateController`.
|
||||
|
||||
Чтобы включить миграции в ваше приложение , вы должны настроить конфигурацию консольного приложения:
|
||||
|
||||
```php
|
||||
return [
|
||||
// ...
|
||||
'controllerMap' => [
|
||||
'arangodb-migrate' => 'explosivebit\arangodb\console\controllers\MigrateController'
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
Ниже приведены примеры использования некоторых команд
|
||||
|
||||
```
|
||||
# создание новой миграции user 'create_user_collection'
|
||||
yii arangodb-migrate/create create_user_collection
|
||||
|
||||
# применить все новые миграции
|
||||
yii arangodb-migrate
|
||||
|
||||
# применить 1у миграцию
|
||||
yii arangodb-migrate/up 1
|
||||
|
||||
# откатить все миграции
|
||||
yii arangodb-migrate/down
|
||||
|
||||
# откатить 1у миграцию
|
||||
yii arangodb-migrate/down 1
|
||||
```
|
||||
|
||||
После создания можно настроить миграции:
|
||||
|
||||
При запуске миграции как в примера ниже создается обычная `document` коллекция с именем миграции, для создания `edge` коллекции необходимо прописать дополнительный параметр `Type => 3`.
|
||||
Пример такого запроса: `$this->createCollection('serices',['Type' => 3]);`. Если нужно создать `document` коллекцию то удалите параметр `'Type' => 3` или вместо цифры 3 встаьте 2.
|
||||
|
||||
```
|
||||
class m170413_210957_create_services_collection extends \explosivebit\arangodb\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
# При запуске миграции создается коллекция "services" с типом edge
|
||||
$this->createCollection('serices',['Type' => 3]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
# При запуске отката миграции удаляется коллекция "services"
|
||||
$this->dropCollection('services');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Использование Debug Panel
|
||||
-----------------
|
||||
|
||||
Добавьте панель ArangoDb в вашу конфигурацию `yii\debug\Module`
|
||||
|
||||
```php
|
||||
return [
|
||||
'bootstrap' => ['debug'],
|
||||
'modules' => [
|
||||
'debug' => 'yii\debug\Module',
|
||||
'panels' => [
|
||||
'arango' => [
|
||||
'class' => 'explosivebit\arangodb\panels\arangodb\ArangoDbPanel',
|
||||
],
|
||||
],
|
||||
...
|
||||
],
|
||||
...
|
||||
];
|
||||
```
|
@@ -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 => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
30
mirzaev/yii2-arangodb/composer.json
Normal file
30
mirzaev/yii2-arangodb/composer.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "elfarqy/yii2-arangodb",
|
||||
"description": "Yii2 arangodb components",
|
||||
"type": "yii2-extension",
|
||||
"keywords": ["yii2","arangodb"],
|
||||
"license": "GPL-3.0+",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ilya Rumyantsev",
|
||||
"email": "explosivebit@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Alvian Burhanuddin",
|
||||
"email": "alvianthelfarqy@gmail.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"yiisoft/yii2": "*",
|
||||
"triagens/arangodb": "~3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"explosivebit\\arangodb\\": ""
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user