9 Commits
2.0.5 ... 2.1.0

Author SHA1 Message Date
df1f06ad80 LEVENSHTEIN 2022-12-18 21:46:08 +10:00
Arsen Mirzaev Tatyano-Muradovich
7a6e6fbada Исправления 2021-03-29 10:20:46 +10:00
Arsen Mirzaev Tatyano-Muradovich
a7abed56d6 Доработка удаления, обновления и генерации запроса 2021-03-22 05:01:43 +10:00
Arsen Mirzaev Tatyano-Muradovich
1592238e5f Исправление метода удаления документа: remove() 2021-03-16 02:41:18 +10:00
Arsen Mirzaev Tatyano-Muradovich
bb4fa52274 foreach(); 2021-03-07 21:03:17 +10:00
Arsen Mirzaev Tatyano-Muradovich
7288baa959 Добавлен оператор "!=", переработка, оптимизация 2021-02-24 08:22:04 +10:00
RedHood
bf44832914 Добавление LET, Traversal. рефакторинг 2021-01-31 11:36:27 +10:00
RedHood
5faa656ede Продолжение разработки поиска по представлениям 2021-01-24 16:35:24 +10:00
RedHood
3355611e20 Начало работы над search() 2021-01-20 13:59:35 +10:00
18 changed files with 888 additions and 231 deletions

View File

@@ -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' => [

View File

@@ -62,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();
@@ -108,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' => [

View File

@@ -26,7 +26,7 @@
],
"require": {
"php": "^8.0.0",
"yiisoft/yii2": "*",
"yiisoft/yii2": "2.*",
"triagens/arangodb": "~3.2"
},
"require-dev": {
@@ -34,12 +34,12 @@
},
"autoload": {
"psr-4": {
"mirzaev\\yii2\\arangodb\\": "mirzaev/yii2-arangodb"
"mirzaev\\yii2\\arangodb\\": "mirzaev/yii2/arangodb"
}
},
"autoload-dev": {
"psr-4": {
"mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2-arangodb/tests"
"mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2/arangodb/tests"
}
}
}

View File

@@ -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 \mirzaev\yii2\arangodb\Migration
{
public function up()
{
$this->createCollection('<?= $className ?>',[]);
}
public function down()
{
$this->dropCollection('<?= $className ?>');
}
}

View File

@@ -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,8 +103,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface
public function all($db = null)
{
$statement = $this->createCommand($db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
$cursor = $statement->execute();
@@ -114,6 +117,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
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)) {

View File

@@ -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;

View File

@@ -2,9 +2,9 @@
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

View File

@@ -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";
}
// Разработать создание графов и представлений
}

View File

@@ -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);

View File

@@ -3,7 +3,7 @@
namespace mirzaev\yii2\arangodb\panels\arangodb;
use mirzaev\yii2\arangodb\panels\arangodb\models\ArangoDb;
use Yii;
use yii;
use yii\debug\Panel;
use yii\log\Logger;
@@ -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,

View File

@@ -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;
?>