1

尝试编写脚本以在 groovy 中打开事务。目前有:

def static transaction(statement, params,success, error)
{
    def http = new HTTPBuilder( 'http://localhost:7474' )
    http.request( POST, JSON ) {
        uri.path = '/db/data/transaction'
        headers.'X-Stream' = 'true'
        requestContentType = JSON
        body =  [ statements : statement , params : params ?: [:] ]

        // uri.query = [ param : 'value' ]

        response.success = { resp, json ->
            if (success) success(json)
            else {
                println "Status ${resp.statusLine} Columns ${json.columns}\nData: ${json.data}"
            }
        }

        response.failure = { resp, message ->
            def result=[status:resp.statusLine.statusCode,statusText:resp.statusLine.reasonPhrase]
            result.headers = resp.headers.collect { h -> [ (h.name) : h.value ] }
            result.message = message
            if (error) {
                error(result)
            } else {
                println "Status: ${result.status} : ${result.statusText} "
                println 'Headers: ${result.headers}'
                println 'Message: ${result.message}'
            }
        }
    }
}
transaction("start n=node(*) return n",[id:56981],{ println "Success: ${it}" },{ println "Error: ${it}" })

但是,我在响应中收到以下错误:

Success: [commit:http://localhost:7474/db/data/transaction/4/commit, results:[], errors:[[code:40001, status:INVALID_REQUEST_FORMAT, message:Unable to deserialize request. Expected [START_OBJECT, FIELD_NAME, START_ARRAY], found [START_OBJECT, FIELD_NAME, VALUE_STRING].]]]

想法?谢谢!

4

2 回答 2

1

请查看https://gist.github.com/7053223。基本上你没有正确构建 json 结构。根据http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html发送包含statements密钥的 json 映射。statement里面有一个包含一个和parameters键的映射数组。比较 l.15 与 l.16-18 以查看差异。

于 2013-10-19T08:49:57.773 回答
0

遇到与 php 相同的问题,statements必须包含以下数组statement

[
    statements => [
        statemant
    ],
    resultDataContents => [
        'row',
        'graph',
    ],
    'includeStats' => true,
]
于 2017-03-18T06:40:12.217 回答