File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,17 @@ public function hasSpace($name)
68
68
return array_key_exists ($ name , $ this ->names );
69
69
}
70
70
71
+ public function once ($ name , $ callback )
72
+ {
73
+ $ key = 'once ' . $ name ;
74
+
75
+ $ rows = $ this ->mapper ->find ('_schema ' , ['key ' => $ key ]);
76
+ if (!count ($ rows )) {
77
+ $ this ->mapper ->create ('_schema ' , ['key ' => $ key ]);
78
+ return $ callback ($ this ->mapper );
79
+ }
80
+ }
81
+
71
82
public function reset ()
72
83
{
73
84
$ this ->names = $ this ->mapper ->getClient ()->evaluate ("
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use Tarantool \Mapper \Mapper ;
3
4
use Tarantool \Mapper \Space ;
4
5
5
6
class SchemaTest extends TestCase
6
7
{
8
+ public function testOnce ()
9
+ {
10
+ $ mapper = $ this ->createMapper ();
11
+ $ this ->clean ($ mapper );
12
+
13
+ $ schema = $ mapper ->getSchema ();
14
+
15
+ $ test = $ schema ->createSpace ('test ' );
16
+ $ test ->addProperty ('name ' , 'str ' );
17
+ $ test ->createIndex ('name ' );
18
+
19
+ $ flag = $ mapper ->findOne ('_schema ' , ['key ' => 'onceinsert ' ]);
20
+ if ($ flag ) {
21
+ $ mapper ->remove ($ flag );
22
+ }
23
+
24
+ $ iterations = 2 ;
25
+ while ($ iterations --) {
26
+ $ schema ->once ('insert ' , function (Mapper $ mapper ) {
27
+ $ mapper ->create ('test ' , ['name ' => 'example row ' ]);
28
+ });
29
+ }
30
+ $ this ->assertCount (1 , $ mapper ->find ('test ' ));
31
+ }
32
+
7
33
public function testSystemMeta ()
8
34
{
9
35
$ mapper = $ this ->createMapper ();
You can’t perform that action at this time.
0 commit comments