Go to file
Ilya Rumyancev (MacBook) 4caca6fc37 For package 2017-04-08 15:59:17 +03:00
console/controllers update remove by Query 2014-08-12 10:33:20 +04:00
panels/arangodb closes #6 closes #7 2014-11-26 09:24:10 +03:00
views change namespace 2014-07-29 10:18:56 +04:00
.gitignore .idea is user-specific and should not appear in a project .gitignore. Consider adding it to the user global .gitignore instead. 2014-11-26 10:00:36 +03:00
ActiveQuery.php update remove by Query 2014-08-12 10:33:20 +04:00
ActiveRecord.php Fixes #9 but beware! Can cause side-effects: we are returning Query instead of calling `->one()` or `->all()` 2015-02-07 11:49:47 +03:00
AqlExpression.php add AqlExpression 2014-10-08 16:34:50 +04:00
Connection.php del ADbConn 2014-10-23 10:30:33 +04:00
Exception.php arango recode 2014-07-29 09:33:21 +04:00
LICENSE Initial commit 2014-06-16 08:29:28 +04:00
Migration.php update remove by Query 2014-08-12 10:33:20 +04:00
Query.php Add method (method emulateExecution from interface QueryInterace) 2017-04-08 15:49:02 +03:00
README.md Add a Bitdeli badge to README 2014-11-23 12:18:02 +00:00
Serializer.php add AqlExpression 2014-10-08 16:34:50 +04:00
composer.json For package 2017-04-08 15:59:17 +03:00

ArangoDb Extension for Yii 2

This extension provides the ArangoDB integration for the Yii2 framework.

Installation

This extension requires ArangoDB PHP Extension

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist devgroup/yii2-arangodb "*"

or add

"devgroup/yii2-arangodb": "*"

to the require section of your composer.json.

General Usage

To use this extension, simply add the following code in your application configuration:

return [
    //....
    'components' => [
        'arangodb' => [
            'class' => '\devgroup\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_USER   => '',
                //triagens\ArangoDb\ConnectionOptions::OPTION_AUTH_PASSWD => '',
            ],
        ],
    ],
];

Using the connection instance you may access databases, collections and documents.

To perform "find" queries, you should use \devgroup\arangodb\Query:

use devgroup\arangodb\Query;

$query = new Query;
// compose the query
$query->select(['name', 'status'])
    ->from('customer')
    ->limit(10);
// execute the query
$rows = $query->all();

Using the ArangoDB ActiveRecord

This extension provides ActiveRecord solution similar ot the \yii\db\ActiveRecord. To declare an ActiveRecord class you need to extend \devgroup\arangodb\ActiveRecord and implement the collectionName and 'attributes' methods:

use devgroup\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'];
    }
}

Note: collection primary key name ('_key') should be always explicitly setup as an attribute.

You can use \yii\data\ActiveDataProvider with \devgroup\arangodb\Query and \devgroup\arangodb\ActiveQuery:

use yii\data\ActiveDataProvider;
use devgroup\arangodb\Query;

$query = new Query;
$query->from('customer')->where(['status' => 2]);
$provider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'pageSize' => 10,
    ]
]);
$models = $provider->getModels();
use yii\data\ActiveDataProvider;
use app\models\Customer;

$provider = new ActiveDataProvider([
    'query' => Customer::find(),
    'pagination' => [
        'pageSize' => 10,
    ]
]);
$models = $provider->getModels();

Using Migrations

ArangoDB migrations are managed via devgroup\arangodb\console\controllers\MigrateController, which is an analog of regular \yii\console\controllers\MigrateController.

In order to enable this command you should adjust the configuration of your console application:

return [
    // ...
    'controllerMap' => [
        'arangodb-migrate' => 'devgroup\arangodb\console\controllers\MigrateController'
    ],
];

Below are some common usages of this command:

# creates a new migration named 'create_user_collection'
yii arangodb-migrate/create create_user_collection

# applies ALL new migrations
yii arangodb-migrate

# reverts the last applied migration
yii arangodb-migrate/down

Using Debug Panel

Add ArangoDb panel to your yii\debug\Module configuration

return [
    'bootstrap' => ['debug'],
    'modules' => [
        'debug' => 'yii\debug\Module',
        'panels' => [
            'arango' => [
                'class' => 'devgroup\arangodb\panels\arangodb\ArangoDbPanel',
            ],
        ],
        ...
    ],
    ...
];

Bitdeli Badge