我有下面的代码,它运行多个语句,第一个语句应该返回一个由第二个语句使用的结果,它是来自android app的调用。
return session.writeTransaction(wrte=>{
let r : any
if(context.auth){
//This Statement returns ID of the node
wrte.run('MATCH (p:Person{identity:{identity}}) CREATE (p)-[po:POST]->(a:Post{post:{post},userName:{userName}}) RETURN ID(a)',
{identity: context.auth.uid, post: data.post, userName: context.auth.token.name })
}
return r as neo4j.v1.StatementResult
})
//how to get the ID from the Last Statement
.then((val) => session.readTransaction(read => {
console.log(val.records[0].get(0))
return read.run('MATCH (p:Post) WHERE id(p) = {any} RETURN p',{any: val.records[0].get(0)})
}))
.then(result => {
session.close();
driver.close()
console.log(result)
var singleRecord = result.records[0]
var dat = singleRecord.get(0)
if(result.records[0] == null){
return null
} else {
return {
"post": dat.properties.post,
"userName":dat.properties.userName,
}
}
}).catch(error => {
session.close()
console.log(error)
driver.close()
throw new functions.https.HttpsError(error,"some error");
})
});
console.log(val.records[0].get(0))
返回未定义,如何正确传递结果以及如何检索 ID?