diff --git a/README.md b/README.md index 6261119..a996da8 100644 --- a/README.md +++ b/README.md @@ -157,19 +157,15 @@ _**Description**_: Available Tarantool constants. * `Tarantool::ITERATOR_LE` - "less than or equal" iterator; * `Tarantool::ITERATOR_GE` - "greater than or equal" iterator; * `Tarantool::ITERATOR_GT` - "greater than" iterator; -* `Tarantool::ITERATOR_BITS_ALL_SET` - check if all given bits are set - (BITSET only); -* `Tarantool::ITERATOR_BITS_ANY_SET` - check if any given bits are set - (BITSET only); -* `Tarantool::ITERATOR_BITS_ALL_NOT_SET` - check if all given bits are - not set (BITSET only); -* `Tarantool::ITERATOR_OVERLAPS` - find points in an n-dimension cube - (RTREE only); +* `Tarantool::ITERATOR_BITS_ALL_SET` - check if all given bits are set (BITSET only); +* `Tarantool::ITERATOR_BITS_ANY_SET` - check if any given bits are set (BITSET only); +* `Tarantool::ITERATOR_BITS_ALL_NOT_SET` - check if all given bits are not set (BITSET only); +* `Tarantool::ITERATOR_OVERLAPS` - find points in an n-dimension cube (RTREE only); * `Tarantool::ITERATOR_NEIGHBOR` - find the nearest points (RTREE only). ## Class Tarantool -``` php +```php Tarantool { public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL @@ -178,25 +174,22 @@ Tarantool { public bool Tarantool::disconnect ( void ) public bool Tarantool::flushSchema ( void ) public bool Tarantool::ping ( void ) - public array Tarantool::select (mixed $space [, mixed $key = -array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = -0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] ) + public array Tarantool::select (mixed $space [, mixed $key = [] + [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 + [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] ) public array Tarantool::insert (mixed $space, array $tuple) public array Tarantool::replace (mixed $space, array $tuple) public array Tarantool::call (string $procedure [, mixed args] ) public array Tarantool::evaluate (string $expression [, mixed args] ) - public array Tarantool::delete (mixed $space, mixed $key [, mixed -$index] ) - public array Tarantool::update (mixed $space, mixed $key, array -$ops [, number $index] ) - public array Tarantool::upsert (mixed $space, mixed $key, array -$ops [, number $index] ) + public array Tarantool::delete (mixed $space, mixed $key [, mixed $index] ) + public array Tarantool::update (mixed $space, mixed $key, array $ops [, number $index] ) + public array Tarantool::upsert (mixed $space, mixed $key, array $ops [, number $index] ) } ``` ### Tarantool::__construct -``` +```php public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL [, string $persistent_id = NULL ] ] ] ] ] ) @@ -217,10 +210,9 @@ _**Return value**_: Tarantool class instance ### Example -``` php +```php $tnt = new Tarantool(); // -> new Tarantool('localhost', 3301); -$tnt = new Tarantool('tarantool.org'); // -> new -Tarantool('tarantool.org', 3301); +$tnt = new Tarantool('tarantool.org'); // -> new Tarantool('tarantool.org', 3301); $tnt = new Tarantool('localhost', 16847); ``` @@ -234,7 +226,7 @@ To initiate and/or test connection, please use [Tarantool::ping](#tarantoolping) ### Tarantool::disconnect -``` php +```php public bool Tarantool::disconnect ( void ) ``` @@ -247,7 +239,7 @@ _**Return value**_: **BOOL**: True ### Tarantool::flushSchema -``` php +```php public bool Tarantool::flushSchema ( void ) ``` @@ -258,7 +250,7 @@ _**Return value**_: **BOOL**: True ### Tarantool::ping -``` php +```php public bool Tarantool::ping ( void ) ``` @@ -271,10 +263,10 @@ _**Return value**_: **BOOL**: True and raises `Exception` on error. ### Tarantool::select -``` php -public array Tarantool::select(mixed $space [, mixed $key = array() [, -mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, -$iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] ) +```php +public array Tarantool::select(mixed $space [, mixed $key = [] +[, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 +[, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] ) ``` _**Description**_: Execute a select query on the Tarantool server. @@ -282,7 +274,7 @@ _**Description**_: Execute a select query on the Tarantool server. _**Parameters**_: * `space`: String/Number, Space ID to select from (mandatory); -* `key`: String/Number or Array, key to select (default: `Array()` i.e. +* `key`: String/Number or Array, key to select (default: `[]` i.e. an empty array which selects everything in the space); * `index`: String/Number, Index ID to select from (default: 0); * `limit`: Number, the maximum number of tuples to return (default: INT_MAX, @@ -304,16 +296,15 @@ _**Return value**_: #### Example -``` php +```php // Selects everything from space 'test' $tnt->select("test"); // Selects from space 'test' by primary key with id == 1 $tnt->select("test", 1); // Same effect as the previous statement -$tnt->select("test", array(1)); -// Selects from space 'test' by secondary key from index 'isec' and == -{1, 'hello'} -$tnt->select("test", array(1, "hello"), "isec"); +$tnt->select("test", [1]); +// Selects from space 'test' by secondary key from index 'isec' and == {1, 'hello'} +$tnt->select("test", [1, "hello"], "isec"); // Selects 100 tuples from space 'test' after skipping 100 tuples $tnt->select("test", null, null, 100, 100); // Selects 100 tuples from space 'test' after skipping 100 tuples, @@ -325,7 +316,7 @@ $tnt->select("test", null, null, 100, 100, Tarantool::ITERATOR_REQ); ### Tarantool::insert, Tarantool::replace -``` php +```php public array Tarantool::insert(mixed $space, array $tuple) public array Tarantool::replace(mixed $space, array $tuple) ``` @@ -345,19 +336,19 @@ _**Return value**_: #### Example -``` php +```php // This will succeed, because no tuples with primary key == 1 are in space 'test'. -$tnt->insert("test", array(1, 2, "something")); +$tnt->insert("test", [1, 2, "something"]); // This will fail, because we have just inserted a tuple with primary key == 1. // The error will be ER_TUPLE_FOUND. -$tnt->insert("test", array(1, 3, "something completely different")); +$tnt->insert("test", [1, 3, "something completely different"]); // This will succeed, because Replace has no problem with duplicate keys. -$tnt->replace("test", array(1, 3, "something completely different")); +$tnt->replace("test", [1, 3, "something completely different"]); ``` ### Tarantool::call -``` php +```php public array Tarantool::call(string $procedure [, mixed args]) ``` @@ -376,14 +367,14 @@ _**Return value**_: #### Example -``` php +```php $tnt->call("test_2"); -$tnt->call("test_3", array(3, 4)); +$tnt->call("test_3", [3, 4]); ``` ### Tarantool::evaluate -``` php +```php public array Tarantool::evaluate(string $expression [, mixed args]) ``` @@ -402,14 +393,14 @@ _**Return value**_: #### Example -``` php +```php $tnt->evaluate("return test_2()"); -$tnt->evaluate("return test_3(...)", array(3, 4)); +$tnt->evaluate("return test_3(...)", [3, 4]); ``` ### Tarantool::delete -``` php +```php public array Tarantool::delete(mixed $space, mixed $key [, mixed $index]) ``` @@ -428,19 +419,18 @@ _**Return value**_: #### Example -``` php +```php // The following code will delete all tuples from space `test` $tuples = $tnt->select("test"); foreach($tuples as $value) { - $tnt->delete("test", array($value[0])); + $tnt->delete("test", [$value[0]]); } ``` ### Tarantool::update -``` php -public array Tarantool::update(mixed $space, mixed $key, array $ops [, -number $index] ) +```php +public array Tarantool::update(mixed $space, mixed $key, array $ops [, number $index] ) ``` _**Description**_: Update a tuple with a given key (in Tarantool, an update @@ -458,22 +448,22 @@ _**Operations**_: * Splice operation - take `field`'th field, replace `length` bytes from `offset` byte with 'list': - ``` - array( + ```php + [ "field" => , "op" => ":", "offset"=> , "length"=> , - "list" => - ), + "list" => , + ], ``` * Numeric operations: - ``` - array( + ```php + [ "field" => , "op" => ("+"|"-"|"&"|"^"|"|"), - "arg" => - ), + "arg" => , + ], ``` - "+" for addition - "-" for subtraction @@ -481,49 +471,49 @@ _**Operations**_: - "^" for bitwise XOR - "|" for bitwise OR * Delete `arg` fields from 'field': - ``` - array( + ```php + [ "field" => , "op" => "#", - "arg" => - ) + "arg" => , + ] ``` * Replace/Insert before operations: - ``` - array( + ```php + [ "field" => , "op" => ("="|"!"), - "arg" => - ) + "arg" => , + ] ``` - "=" replace `field`'th field with 'arg' - "=" insert 'arg' before `field`'th field -``` -array( - array( +```php +[ + [ "field" => , "op" => ":", "offset"=> , "length"=> , - "list" => - ), - array( + "list" => , + ], + [ "field" => , "op" => ("+"|"-"|"&"|"^"|"|"), - "arg" => - ), - array( + "arg" => , + ], + [ "field" => , "op" => "#", - "arg" => - ), - array( + "arg" => , + ], + [ "field" => , "op" => ("="|"!"), - "arg" => - ) -) + "arg" => , + ], +] ``` _**Return value**_: @@ -533,66 +523,65 @@ _**Return value**_: #### Example -``` php -$tnt->update("test", 1, array( - array( +```php +$tnt->update("test", 1, [ + [ "field" => 1, "op" => "+", - "arg" => 16 - ), - array( + "arg" => 16, + ], + [ "field" => 3, "op" => "=", - "arg" => 98 - ), - array( + "arg" => 98, + ], + [ "field" => 4, "op" => "=", "arg" => 0x11111, - ), -)); -$tnt->update("test", 1, array( - array( + ], +]); +$tnt->update("test", 1, [ + [ "field" => 3, "op" => "-", - "arg" => 10 - ), - array( + "arg" => 10, + ], + [ "field" => 4, "op" => "&", "arg" => 0x10101, - ) -)); -$tnt->update("test", 1, array( - array( + ], +]); +$tnt->update("test", 1, [ + [ "field" => 4, "op" => "^", "arg" => 0x11100, - ) -)); -$tnt->update("test", 1, array( - array( + ], +]); +$tnt->update("test", 1, [ + [ "field" => 4, "op" => "|", "arg" => 0x00010, - ) -)); -$tnt->update("test", 1, array( - array( + ], +]); +$tnt->update("test", 1, [ + [ "field" => 2, "op" => ":", "offset" => 2, "length" => 2, - "list" => "rrance and phillipe show" - ) -)); + "list" => "rrance and phillipe show", + ], +]); ``` ### Tarantool::upsert -``` php -public array Tarantool::upsert(mixed $space, array $tuple, array $ops [, -number $index] ) +```php +public array Tarantool::upsert(mixed $space, array $tuple, array $ops [, number $index] ) ``` _**Description**_: Update or Insert command (if a tuple with primary key @@ -616,14 +605,14 @@ _**Return value**_: #### Example -``` php -$tnt->upsert("test", array(124, 10, "new tuple"), array( - array( +```php +$tnt->upsert("test", [124, 10, "new tuple"], [ + [ "field" => 1, "op" => "+", - "arg" => 10 - ) -)); + "arg" => 10, + ], +]); ``` ## Deprecated