sandrokeil / arangodb-php-driver

A PHP extension for ArangoDB with fuerte and velocypack :rocket:
5 stars 1 forks source link

Check transaction response with velocypack #39

Open sandrokeil opened 6 years ago

sandrokeil commented 6 years ago

We should find a possibility to replace the Type inspectors with working directly on velocypack data for faster checks. This is especially needed for lager transactions/responses.

Succesful response

{
    "code": 200,
    "error": false,
    "result": {
        "rId0": [
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000001",
                "_key": "100000000000000001",
                "_rev": "_WAf0iN----"
            },
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000002",
                "_key": "100000000000000002",
                "_rev": "_WAf0iN---_"
            }
        ]
    }
}

Error response single type

Attention: Root error key is false, but individual result has "error": true,.

{
    "code": 200,
    "error": false,
    "result": {
        "rId0": [
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000001",
                "_key": "100000000000000001",
                "_rev": "_WAg_9aK---"
            },
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000002",
                "_key": "100000000000000002",
                "_rev": "_WAg_9aK--_"
            },
            {
                "error": true,
                "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
                "errorNum": 1210
            }
        ]
    }
}

Error response multiple types

Attention: Root error key is false, but individual result has "error": true,.

{
    "code": 200,
    "error": false,
    "result": {
        "rId0": [
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000001",
                "_key": "100000000000000001",
                "_rev": "_WAgC_wq---"
            },
            {
                "_id": "c878c0b7e51ecaab95c511fc816ad2a70c9418208/100000000000000002",
                "_key": "100000000000000002",
                "_rev": "_WAgC_wq--_"
            }
        ],
        "rId1": [
            {
                "error": true,
                "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
                "errorNum": 1210
            },
            {
                "error": true,
                "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
                "errorNum": 1210
            }
        ]
    }
}

I would suggest to only find the first error object and transform it to an exception. A method to get all errors would be nice too. The error object under result has the following structure:

{
    "error": true,
    "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
    "errorNum": 1210
}

Would be nice if there is a faster lookup instead of iterating through each result.

sandrokeil commented 6 years ago

We should add the silent option for InsertDocument calls, because this simplifies error check. rId0 has the value true. :tada:

{
    "code": 200,
    "error": false,
    "result": {
        "rId0": true,
        "rId1": [
            {
                "error": true,
                "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
                "errorNum": 1210
            },
            {
                "error": true,
                "errorMessage": "unique constraint violated - in index 0 of type primary over [\"_key\"]",
                "errorNum": 1210
            }
        ]
    }
}
sandrokeil commented 6 years ago

We get fast access with Working with Arrays and Objects.