1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\Query; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Query\Operation\DbCreate; |
7
|
|
|
use TBolier\RethinkQL\Query\Operation\DbDrop; |
8
|
|
|
use TBolier\RethinkQL\Query\Operation\DbList; |
9
|
|
|
use TBolier\RethinkQL\Query\Operation\TableCreate; |
10
|
|
|
use TBolier\RethinkQL\Query\Operation\TableDrop; |
11
|
|
|
use TBolier\RethinkQL\Query\Operation\TableList; |
12
|
|
|
use TBolier\RethinkQL\RethinkInterface; |
13
|
|
|
|
14
|
|
|
class Database extends AbstractQuery implements DatabaseInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var QueryInterface |
18
|
|
|
*/ |
19
|
|
|
private $query; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param RethinkInterface $rethink |
23
|
|
|
* @param MessageInterface $message |
24
|
|
|
*/ |
25
|
13 |
|
public function __construct(RethinkInterface $rethink, MessageInterface $message) |
26
|
|
|
{ |
27
|
13 |
|
parent::__construct($rethink, $message); |
28
|
|
|
|
29
|
13 |
|
$this->dbList(); |
30
|
13 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
12 |
|
public function dbCreate(string $name): DatabaseInterface |
36
|
|
|
{ |
37
|
12 |
|
$this->query = new DbCreate($this->rethink, $this->message, $name); |
38
|
|
|
|
39
|
12 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
13 |
|
public function dbDrop(string $name): DatabaseInterface |
46
|
|
|
{ |
47
|
13 |
|
$this->query = new DbDrop($this->rethink, $this->message, $name); |
48
|
|
|
|
49
|
13 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
13 |
|
public function dbList(): DatabaseInterface |
56
|
|
|
{ |
57
|
13 |
|
$this->query = new DbList($this->rethink, $this->message); |
58
|
|
|
|
59
|
13 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
11 |
|
public function tableList(): DatabaseInterface |
66
|
|
|
{ |
67
|
11 |
|
$this->query = new TableList($this->rethink, $this->message); |
68
|
|
|
|
69
|
11 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
12 |
|
public function tableCreate(string $name): DatabaseInterface |
76
|
|
|
{ |
77
|
12 |
|
$this->query = new TableCreate($this->rethink, $this->message, $name); |
78
|
|
|
|
79
|
12 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @inheritdoc |
84
|
|
|
*/ |
85
|
11 |
|
public function tableDrop(string $name): DatabaseInterface |
86
|
|
|
{ |
87
|
11 |
|
$this->query = new TableDrop($this->rethink, $this->message, $name); |
88
|
|
|
|
89
|
11 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritdoc |
94
|
|
|
*/ |
95
|
13 |
|
public function toArray(): array |
96
|
|
|
{ |
97
|
13 |
|
return $this->query->toArray(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|