Completed
Push — master ( 33bc8d...136dfe )
by Dmitry
03:12 queued 15s
created

CreateSequence::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tarantool\Mapper\Procedure;
6
7
use Exception;
8
use Tarantool\Mapper\Plugin\Sequence;
9
use Tarantool\Mapper\Procedure;
10
use Tarantool\Mapper\Space;
11
12
class CreateSequence extends Procedure
13
{
14
    public function execute(string $space, string $primaryIndex, int $primaryField)
15
    {
16
        $this($space, $primaryIndex, $primaryField);
17
    }
18
19
    public function getBody() : string
20
    {
21
        return <<<LUA
22
        if box.sequence[space] == nil then
23
            local last = 0
24
            local tuple = box.space[space].index[primary_index]:max()
25
            if tuple ~= nil then
26
                last = tuple[primary_field]
27
            end
28
            box.schema.sequence.create(space, { start = last + 1 })
29
        end
30
LUA;
31
    }
32
33
    public function getName() : string
34
    {
35
        return 'mapper_create_sequence';
36
    }
37
38
    public function getParams() : array
39
    {
40
        return ['space', 'primary_index', 'primary_field'];
41
    }
42
}
43