tarantool-php / client

PHP client for Tarantool.
MIT License
67 stars 22 forks source link

Return an associative array of data #70

Open chelsEg opened 3 years ago

chelsEg commented 3 years ago

Hello.

In our projects we use Your library for connect to Tarantool.

Would be great if select function return associative array.

At the moment in our cases we have something like this:

$result = $client()->getSpace('test_space')->select(Criteria::key([1]));

print_r($result);

/*
    Array
    (
        [0] => Array
            (
                [0] => 1
                [1] => Test
                [2] => Test
                [3] => https://www.google.com/
                [4] => 1
                [5] => 0
                [6] => 1
                [7] => 2
                [8] => 1
                [9] => 1
                [10] => 1
            )
    )
 */

After that we associate index number with field name for comfort and easy usage in our code.

Proposal:

For more comfort usage, adding boolean parameter $associative with default value => false to select function.

$result = $client()->getSpace('test_space')->select(Criteria::key([1]), true);

print_r($result);

/*
    Array
    (
        [0] => Array
        (
            [field_1] => 1
            [field_2] => Test
            [field_3] => Test
            [field_4] => https://www.google.com/
            [field_5] => 1
            [field_6] => 0
            [field_7] => 1
            [field_8] => 2
            [field_9] => 1
            [field_10] => 1
            [field_11] => 1
        )
    )
*/

Thanks!

dehlirious commented 8 months ago

Personally, I just store a string, which is the serialized contents of my array. ( serialized(['test'=>'test'] ) Unserialize it when I grab it, and I have no issues. ( unserialize() )