Skip to content
Permalink
Browse files

toolkit shortcuts using pool

  • Loading branch information...
Dmitry Krokhin
Dmitry Krokhin committed Sep 17, 2018
1 parent 8ebf4eb commit d9df1086dc0d93343e8d248c669971a663ad50dc
Showing with 16 additions and 7 deletions.
  1. +1 −1 composer.json
  2. +15 −6 src/Toolkit.php
@@ -12,7 +12,7 @@
"ramsey/uuid": "3.7.3",
"rybakit/msgpack": "v0.5.3",
"smi2/phpclickhouse": "1.2.3",
"tarantool/mapper": "^4.3.19",
"tarantool/mapper": "^4.3.20",
"tarantool/queue": "v0.6.1"
},
"require-dev": {
@@ -4,6 +4,7 @@
use Tarantool\Mapper\Entity;
use Tarantool\Mapper\Mapper;
use Tarantool\Mapper\Pool;
use Tarantool\Queue\Queue;
trait Toolkit
@@ -17,7 +18,7 @@ public function __construct(Application $app)
protected function create(string $space, array $data) : Entity
{
return $this->get(Mapper::class)->create($space, $data);
return $this->getRepository($space)->create($data)->save();
}
protected function dispatch(string $job, array $params = [], string $service = null)
@@ -27,22 +28,22 @@ protected function dispatch(string $job, array $params = [], string $service = n
protected function find(string $space, $params = []) : array
{
return $this->get(Mapper::class)->find($space, $params);
return $this->getRepository($space)->find($params);
}
protected function findOne(string $space, $params = []) : ?Entity
{
return $this->get(Mapper::class)->findOne($space, $params);
return $this->getRepository($space)->findOne($params);
}
protected function findOrCreate(string $space, $params = []) : Entity
{
return $this->get(Mapper::class)->findOrCreate($space, $params);
return $this->getRepository($space)->findOrCreate($params);
}
protected function findOrFail(string $space, $params = []) : Entity
{
return $this->get(Mapper::class)->findOrFail($space, $params);
return $this->getRepository($space)->findOrFail($params);
}
protected function fire(string $event, array $context)
@@ -65,6 +66,14 @@ protected function getMapper()
return $this->get(Mapper::class);
}
protected function getRepository($space)
{
if (strpos($space, '.') !== false) {
return $this->get(Pool::class)->getRepository($space);
}
return $this->get(Mapper::class)->getRepository($space);
}
protected function getQueue($tube)
{
$alias = "queue.$tube";
@@ -83,7 +92,7 @@ protected function getQueue($tube)
protected function remove(string $space, array $params = [])
{
return $this->get(Mapper::class)->remove($space, $params);
return $this->getRepository($space)->remove($params);
}
protected function select($fields, string $table, array $params)

0 comments on commit d9df108

Please sign in to comment.
You can’t perform that action at this time.