Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
453cac0b77 | ||
|
3e095e14f7 | ||
|
577bc837d8 | ||
|
9f7ce7e9b6 | ||
|
4e04d09b32 | ||
|
d0ce9e47af | ||
|
b2088df8fb | ||
|
cb1388722c | ||
![]() |
11be80b0ad | ||
![]() |
48a8908afd | ||
![]() |
8f5f5b44de | ||
![]() |
8e7972d933 | ||
|
e7da9978d0 | ||
|
4daa93799e |
|
@ -1 +1,3 @@
|
||||||
vendor
|
vendor
|
||||||
|
composer.lock
|
||||||
|
!.gitignore
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
@ -0,0 +1,3 @@
|
||||||
|
# PHP 8.3 Framework for working with ArangoDB
|
||||||
|
|
||||||
|
🤟 Very simple and flexible, easy to scale and integrate
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "mirzaev/arangodb",
|
"name": "mirzaev/arangodb",
|
||||||
"description": "Реализация управления хранилищем данных ArangoDB",
|
"description": "Simple PHP-framework for ArangoDB",
|
||||||
|
"readme": "README.md",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"ArangoDB"
|
"ArangoDB"
|
||||||
],
|
],
|
||||||
"type": "library",
|
"type": "framework",
|
||||||
"license": "WTFPL",
|
"license": "WTFPL",
|
||||||
"homepage": "https://git.hood.su/mirzaev/arangodb",
|
"homepage": "https://git.hood.su/mirzaev/arangodb",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -15,8 +16,19 @@
|
||||||
"role": "Developer"
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"support": {
|
||||||
|
"email": "arsen@mirzaev.sexy",
|
||||||
|
"wiki": "https://git.mirzaev.sexy/mirzaev/arangodb/manual",
|
||||||
|
"issues": "https://git.mirzaev.sexy/mirzaev/arangodb/issues"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "funding",
|
||||||
|
"url": "https://fund.mirzaev.sexy"
|
||||||
|
}
|
||||||
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.2",
|
||||||
"triagens/arangodb": "~3.8"
|
"triagens/arangodb": "~3.8"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,51 +4,60 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace mirzaev\arangodb;
|
namespace mirzaev\arangodb;
|
||||||
|
|
||||||
use mirzaev\arangodb\terminal;
|
// Files of the project
|
||||||
|
use mirzaev\arangodb\connection,
|
||||||
|
mirzaev\arangodb\terminal,
|
||||||
|
mirzaev\arangodb\enumerations\collection\type;
|
||||||
|
|
||||||
use ArangoDBClient\Connection as _connection;
|
// Library for ArangoDB
|
||||||
use ArangoDBClient\Collection as _collection;
|
use ArangoDBClient\Statement as _statement,
|
||||||
use ArangoDBClient\Statement as _statement;
|
ArangoDBClient\Document as _document,
|
||||||
use ArangoDBClient\Document as _document;
|
ArangoDBClient\CollectionHandler as _collection_handler,
|
||||||
use ArangoDBClient\CollectionHandler as _collection_handler;
|
ArangoDBClient\Cursor as cursor;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Коллекция
|
* Collection
|
||||||
*
|
*
|
||||||
* @package mirzaev\arangodb
|
* @package mirzaev\arangodb
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
class collection
|
class collection
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Инициализация
|
* Initialize a collection
|
||||||
*
|
*
|
||||||
* @param _connection $session Сессия соединения с базой данных
|
* @param string $collection Name of the collection
|
||||||
* @param string $name Название
|
* @param type $type Type of the collection
|
||||||
* @param bool $edge Обрабатывать как ребро? (иначе: вершина)
|
|
||||||
* @param ?terminal $terminal Инстанция терминала
|
* @param ?terminal $terminal Инстанция терминала
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
*
|
*
|
||||||
* @return string|null Идентификатор коллекции
|
* @return string|null Identifier of the collection
|
||||||
*/
|
*/
|
||||||
public static function init(_connection $session, string $name, bool $edge = false, ?terminal $terminal = null): ?string
|
public static function initialize(string $name, type $type = type::document, ?terminal $terminal = null, array &$errors = []): ?string
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
// Инициализация
|
// Инициализация
|
||||||
$collections = new _collection_handler($session);
|
$collections = new _collection_handler(connection::$session);
|
||||||
|
|
||||||
if (!$collections->has($name)) {
|
if (!$collections->has($name)) {
|
||||||
// Не найдана коллекция
|
// Не найдана коллекция
|
||||||
|
|
||||||
// Запись в вывод
|
// Запись в вывод
|
||||||
if ($terminal instanceof terminal) $terminal::write("Коллекция \"$name\" не найдена");
|
if ($terminal instanceof terminal) $terminal::write("Not found $type collection: $name");
|
||||||
|
|
||||||
// Запись коллекции на сервер и его ответ в буфер возврата
|
// Запись коллекции на сервер и его ответ в буфер возврата
|
||||||
$id = $collections->create($name, ['type' => $edge ? _collection::TYPE_EDGE : _collection::TYPE_DOCUMENT]);
|
$id = $collections->create($name, ['type' => $type->code()]);
|
||||||
|
|
||||||
if ($collections->has($name)) {
|
if ($collections->has($name)) {
|
||||||
// Коллекция найдена (записана)
|
// Коллекция найдена (записана)
|
||||||
|
|
||||||
// Запись в вывод
|
// Запись в вывод
|
||||||
if ($terminal instanceof terminal) $terminal::write("Создана коллекция \"$name\" с типом " . ($edge ? 'ребро' : 'документ'));
|
if ($terminal instanceof terminal) $terminal::write("Created $type collection: $name");
|
||||||
|
|
||||||
// Возврат идентификатора коллекции
|
// Возврат идентификатора коллекции
|
||||||
return $id;
|
return $id;
|
||||||
|
@ -59,60 +68,137 @@ class collection
|
||||||
// Возврат идентификатора коллекции
|
// Возврат идентификатора коллекции
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Поиск
|
* Execute
|
||||||
*
|
*
|
||||||
* @param _connection $session Сессия соединения с базой данных
|
* @param string $query Query (AQL)
|
||||||
* @param string $query AQL-запрос
|
* @param array $parameters Binded parameters for placeholders [placholder => parameter]
|
||||||
|
* @param bool $flat Not implement record?
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
*
|
*
|
||||||
* @return _document|null Инстанция документа
|
* @return _document|array|string|int|null Instance of the document
|
||||||
*/
|
*/
|
||||||
public static function search(_connection $session, string $query): ?_document
|
public static function execute(string $query, array $parameters = [], bool $flat = false, array &$errors = []): _document|string|array|int|null
|
||||||
{
|
{
|
||||||
// Поиск журнала
|
try {
|
||||||
$journal = (new _statement(
|
// Statement instance initialization
|
||||||
$session,
|
$instance = new _statement(
|
||||||
|
connection::$session,
|
||||||
[
|
[
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
"batchSize" => 1000,
|
'batchSize' => 1000,
|
||||||
"sanitize" => true
|
'sanitize' => true,
|
||||||
|
cursor::ENTRY_FLAT => $flat
|
||||||
]
|
]
|
||||||
))->execute();
|
);
|
||||||
|
|
||||||
|
// Binds application
|
||||||
|
$instance->bind($parameters);
|
||||||
|
|
||||||
|
// Sending the request
|
||||||
|
$response = $instance->execute();
|
||||||
|
|
||||||
// Инициализация буфера вывода
|
// Инициализация буфера вывода
|
||||||
$buffer = [];
|
$buffer = [];
|
||||||
|
|
||||||
foreach ($journal as $key => $value) {
|
foreach ($response->getAll() as $key => $value) {
|
||||||
$buffer[$key] = $value;
|
$buffer[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $buffer[0] ?? null;
|
// Exit (success)
|
||||||
|
return is_array($buffer) && count($buffer) > 1 ? $buffer : $buffer[0] ?? null;
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Очистка
|
* Truncate
|
||||||
*
|
*
|
||||||
* @param _connection $session Сессия соединения с базой данных
|
* @param string $name Name of the collection
|
||||||
* @param string $name Название
|
* @param array &$errors Registry of errors
|
||||||
*
|
*
|
||||||
* @return bool Статус выполнения
|
* @return bool Статус выполнения
|
||||||
*/
|
*/
|
||||||
public static function truncate(_connection $session, string $name): bool
|
public static function truncate(string $collection, array &$errors = []): bool
|
||||||
{
|
{
|
||||||
// Инициализация
|
try {
|
||||||
$collections = new _collection_handler($session);
|
// Initizlizing of the collection handler
|
||||||
|
$collections = new _collection_handler(connection::$session);
|
||||||
|
|
||||||
if ($collections->has($name)) {
|
if ($collections->has($collection)) {
|
||||||
// Найдена коллекция
|
// Fount the collection
|
||||||
|
|
||||||
// Очистка
|
// Truncate and exit (success)
|
||||||
return $collections->truncate($name);
|
return $collections->truncate($collection);
|
||||||
|
}
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count documents in ArangoDB
|
||||||
|
*
|
||||||
|
* @param string $collection Name of the collection
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
|
*
|
||||||
|
* @return int|null Amount of documents in ArangoDB
|
||||||
|
*/
|
||||||
|
public static function count(string $collection, array &$errors = []): ?int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Count and exit (success)
|
||||||
|
return static::execute(
|
||||||
|
<<<'AQL'
|
||||||
|
RETURN LENGTH(@@collection)
|
||||||
|
AQL,
|
||||||
|
[
|
||||||
|
'@collection' => $collection
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,21 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace mirzaev\arangodb;
|
namespace mirzaev\arangodb;
|
||||||
|
|
||||||
use ArangoDBClient\Connection as _connection;
|
// Library for ArangoDB
|
||||||
use ArangoDBClient\Exception as _exception;
|
use ArangoDBClient\Connection as _connection,
|
||||||
use ArangoDBClient\UpdatePolicy as _update;
|
ArangoDBClient\Exception as _exception,
|
||||||
use ArangoDBClient\ConnectionOptions as _options;
|
ArangoDBClient\UpdatePolicy as _update,
|
||||||
|
ArangoDBClient\ConnectionOptions as _options;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
use exception;
|
use exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Подключение
|
* Connection
|
||||||
*
|
*
|
||||||
* @package mirzaev\arangodb
|
* @package mirzaev\arangodb
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class connection
|
final class connection
|
||||||
|
@ -82,12 +86,14 @@ final class connection
|
||||||
/**
|
/**
|
||||||
* Сессия соединения
|
* Сессия соединения
|
||||||
*/
|
*/
|
||||||
protected _connection $session;
|
public static _connection $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Конструктор
|
* Конструктор
|
||||||
*
|
*
|
||||||
* @param array $settings Настройки
|
* @param array $settings Настройки
|
||||||
|
*
|
||||||
|
* @todo ПЕРЕДЕЛАТЬ ПОЛНОСТЬЮ
|
||||||
*/
|
*/
|
||||||
public function __construct(array $settings = null)
|
public function __construct(array $settings = null)
|
||||||
{
|
{
|
||||||
|
@ -112,7 +118,7 @@ final class connection
|
||||||
}
|
}
|
||||||
|
|
||||||
// Подключение
|
// Подключение
|
||||||
$this->session = new _connection([
|
static::$session = new _connection([
|
||||||
_options::OPTION_ENDPOINT => $this->adress,
|
_options::OPTION_ENDPOINT => $this->adress,
|
||||||
_options::OPTION_DATABASE => $this->storage,
|
_options::OPTION_DATABASE => $this->storage,
|
||||||
_options::OPTION_AUTH_TYPE => $this->auth,
|
_options::OPTION_AUTH_TYPE => $this->auth,
|
||||||
|
@ -171,7 +177,6 @@ final class connection
|
||||||
'reconnect' => $this->reconnect,
|
'reconnect' => $this->reconnect,
|
||||||
'create' => $this->create,
|
'create' => $this->create,
|
||||||
'update', 'policy' => $this->update,
|
'update', 'policy' => $this->update,
|
||||||
'session' => $this->session,
|
|
||||||
'journal' => $this->journal,
|
'journal' => $this->journal,
|
||||||
default => throw new exception("Свойство \"$name\" не найдено", 404)
|
default => throw new exception("Свойство \"$name\" не найдено", 404)
|
||||||
};
|
};
|
||||||
|
@ -196,7 +201,6 @@ final class connection
|
||||||
'reconnect' => isset($this->reconnect),
|
'reconnect' => isset($this->reconnect),
|
||||||
'create' => isset($this->create),
|
'create' => isset($this->create),
|
||||||
'update', 'policy' => isset($this->update),
|
'update', 'policy' => isset($this->update),
|
||||||
'session' => isset($this->session),
|
|
||||||
'journal' => isset($this->journal),
|
'journal' => isset($this->journal),
|
||||||
default => throw new exception("Свойство \"$name\" не найдено", 404)
|
default => throw new exception("Свойство \"$name\" не найдено", 404)
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,43 +4,63 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace mirzaev\arangodb;
|
namespace mirzaev\arangodb;
|
||||||
|
|
||||||
use mirzaev\arangodb\terminal;
|
// Files of the project
|
||||||
|
use mirzaev\arangodb\terminal,
|
||||||
|
mirzaev\arangodb\connection,
|
||||||
|
mirzaev\arangodb\enumerations\collection\type;
|
||||||
|
|
||||||
use ArangoDBClient\Connection as _connection;
|
// Librsry for ArangoDB
|
||||||
use ArangoDBClient\Document as _document;
|
use ArangoDBClient\Connection as _connection,
|
||||||
use ArangoDBClient\Edge as _edge;
|
ArangoDBClient\Document as _document,
|
||||||
use ArangoDBClient\DocumentHandler as _document_handler;
|
ArangoDBClient\Edge as _edge,
|
||||||
use ArangoDBClient\EdgeHandler as _edge_handler;
|
ArangoDBClient\DocumentHandler as _document_handler,
|
||||||
|
ArangoDBClient\EdgeHandler as _edge_handler;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Документ
|
* Document
|
||||||
|
*
|
||||||
|
* Handlers of document in ArangoDB
|
||||||
*
|
*
|
||||||
* @package mirzaev\arangodb
|
* @package mirzaev\arangodb
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
class document
|
class document
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Записать
|
* Write
|
||||||
*
|
*
|
||||||
* @param _connection $session Сессия соединения с базой данных
|
|
||||||
* @param string $collection Коллекция
|
* @param string $collection Коллекция
|
||||||
* @param ?array $data Данные
|
* @param ?array $data Данные
|
||||||
* @param bool $check Проверка на запись в базу данных
|
* @param bool $check Проверка на запись в базу данных
|
||||||
* @param ?terminal $terminal Инстанция терминала
|
* @param ?terminal $terminal Instance of the terminal
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
*
|
*
|
||||||
* @return string|null Идентификатор
|
* @return string|null Идентификатор
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* 1. Bind parameters
|
||||||
*/
|
*/
|
||||||
public static function write(_connection $session, string $collection, ?array $data = [], bool $check = false, ?terminal $terminal = null): ?string
|
public static function write(
|
||||||
{
|
string $collection,
|
||||||
|
?array $data = [],
|
||||||
|
bool $check = false,
|
||||||
|
?terminal $terminal = null,
|
||||||
|
array &$errors = []
|
||||||
|
): string|null|false {
|
||||||
|
try {
|
||||||
// Инициализация коллекции
|
// Инициализация коллекции
|
||||||
collection::init($session, $collection, isset($data['_from'], $data['_to']));
|
collection::initialize($collection, isset($data['_from'], $data['_to']) ? type::edge : type::document);
|
||||||
|
|
||||||
if (isset($data['_from'], $data['_to'])) {
|
if (isset($data['_from'], $data['_to'])) {
|
||||||
// Ребро
|
// Ребро
|
||||||
|
|
||||||
// Инициализация обработчика рёбер
|
// Инициализация обработчика рёбер
|
||||||
$documents = new _edge_handler($session);
|
$documents = new _edge_handler(connection::$session);
|
||||||
|
|
||||||
// Инициализация ребра
|
// Инициализация ребра
|
||||||
$document = new _edge();
|
$document = new _edge();
|
||||||
|
@ -55,13 +75,16 @@ class document
|
||||||
// Вершина
|
// Вершина
|
||||||
|
|
||||||
// Инициализация обработчика вершин
|
// Инициализация обработчика вершин
|
||||||
$documents = new _document_handler($session);
|
$documents = new _document_handler(connection::$session);
|
||||||
|
|
||||||
// Инициализация вершины
|
// Инициализация вершины
|
||||||
$document = new _document();
|
$document = new _document();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (['created' => time()] + $data as $key => $value) {
|
// Инициализация даты создания
|
||||||
|
$created = time();
|
||||||
|
|
||||||
|
foreach (['created' => $created, 'updated' => $created] + $data as $key => $value) {
|
||||||
// Перебор параметров
|
// Перебор параметров
|
||||||
|
|
||||||
// Запись в инстанцию документа
|
// Запись в инстанцию документа
|
||||||
|
@ -87,22 +110,80 @@ class document
|
||||||
|
|
||||||
// Возврат идентификатора коллекции
|
// Возврат идентификатора коллекции
|
||||||
return $id;
|
return $id;
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Обновить
|
* Update
|
||||||
*
|
*
|
||||||
* @param _connection $session Сессия соединения с базой данных
|
* @param array &$errors Registry of errors
|
||||||
* @param _document $document Инстанция документа вершины
|
* @param _document $document Instance of the document
|
||||||
*
|
*
|
||||||
* @return bool Статус обработки
|
* @return bool Has the document been updated?
|
||||||
*/
|
*/
|
||||||
public static function update(_connection $session, _document $document): bool
|
public static function update(_document $document, array &$errors = []): bool
|
||||||
{
|
{
|
||||||
// Инициализация обработчика вершин
|
try {
|
||||||
$documents = new _document_handler($session);
|
// Initialize the handler of documents
|
||||||
|
$documents = new _document_handler(connection::$session);
|
||||||
|
|
||||||
// Запись в базу данных
|
// Writing date of the updating to the updating document
|
||||||
|
$document->set('updated', time());
|
||||||
|
|
||||||
|
// Writing and exit (success)
|
||||||
return $documents->update($document);
|
return $documents->update($document);
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param _document $document Instance of the document
|
||||||
|
* @param array &$errors Registry of errors
|
||||||
|
*
|
||||||
|
* @return bool Has the document been deleted?
|
||||||
|
*/
|
||||||
|
public static function delete(_document $document, array &$errors = []): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Initialize the handler of documents
|
||||||
|
$documents = new _document_handler(connection::$session);
|
||||||
|
|
||||||
|
// Delete abd exit (success)
|
||||||
|
return $documents->remove($document);
|
||||||
|
} catch (exception $e) {
|
||||||
|
// Writing to registry of errors
|
||||||
|
$errors[] = [
|
||||||
|
'text' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'stack' => $e->getTrace()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace mirzaev\arangodb\enumerations\collection;
|
||||||
|
|
||||||
|
// Library for ArangoDB
|
||||||
|
use ArangoDBClient\Collection as _collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types of collections
|
||||||
|
*
|
||||||
|
* @package mirzaev\arangodb\enumerations\collection
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum type
|
||||||
|
{
|
||||||
|
case document;
|
||||||
|
case edge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read code of the type from library for ArangoDB
|
||||||
|
*
|
||||||
|
* @return int Code of the type
|
||||||
|
*/
|
||||||
|
public function code(): int
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
type::document => _collection::TYPE_DOCUMENT,
|
||||||
|
type::edge => _collection::TYPE_EDGE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,12 +4,26 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace mirzaev\arangodb;
|
namespace mirzaev\arangodb;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminal
|
||||||
|
*
|
||||||
|
* lol sorry
|
||||||
|
* i did not want to do this
|
||||||
|
*
|
||||||
|
* @package mirzaev\arangodb
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
class terminal
|
class terminal
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Префикс
|
* Префикс
|
||||||
*/
|
*/
|
||||||
protected const PREFIX = 'arangodb';
|
protected const string PREFIX = 'arangodb';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Запись в вывод
|
* Запись в вывод
|
||||||
|
|
Loading…
Reference in New Issue