简体   繁体   English

从javascript异步查询neo4j

[英]Async queries to neo4j from javascript

Up to now, I managed to have my function that run the queries being able to return a result immediately.到目前为止,我设法让运行查询的函数能够立即返回结果。 so the structure of my functions where所以我的函数结构在哪里

var session = driver.session();
return session.run([QUERY]).then(result=> return result.record.map ....)

I now have a bigger query and maybe for that reason, I end up having the query function return a Premise I switched then to an async function with the following structure我现在有一个更大的查询,也许正是因为这个原因,我最终让查询函数返回了一个前提,然后我切换到了一个具有以下结构的异步函数

 var session = driver.session();
await session.run([QUERY]).then(result=> results= result.record.map ....)
return results

But then I get regeneratorRuntime is not defined at runtime in the console of the browser.但是后来我在浏览器的控制台中在运行时未定义 regeneratorRuntime

As environment config, I have the one of the sample movies-javascript-bolt-master作为环境配置,我有一个示例电影-javascript-bolt-master

Thank You谢谢你

You don't necessarily need async / await in order to make your code work.您不一定需要async / await才能使您的代码工作。 This is just syntaxic sugar but the mechanism under the hood is exactly the same, and it does not allow to do more things (an async function is just a function returning a Promise ).这只是语法糖,但幕后机制完全相同,它不允许做更多的事情( async function只是一个返回Promise的函数)。 It just allows to make the code more compact and readable.它只是允许使代码更紧凑和可读。

If you still want to use this syntax, you'll have to update Webpack and Babel to their latest versions, and update their configurations (use babel-presets-2017 which allows to transform async/await to generator functions in order to enable older runtimes to run your code).如果你仍然想使用这个语法,你必须将 Webpack 和 Babel 更新到它们的最新版本,并更新它们的配置(使用babel-presets-2017允许将 async/await 转换为生成器函数以启用旧的运行时运行您的代码)。

The error code you have is related to this particular feature of Babel (you could also disable it completely).你的错误代码与 Babel 的这个特殊功能有关(你也可以完全禁用它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM