noe4j javascript示例

时间:2018-01-30 22:03:03

标签: javascript sql neo4j

我无法找到的是使用javascript的neo4j的简单示例(没有第三方)。我有neo4j的桌面工作,并得到一个第三方图形工具工作的例子(该示例似乎将请求放在DIV的textarea中并将请求发送到图形api并生成图表)。

我非常熟悉MYSQL,其他SQL交互但是与neo4j交互时遇到问题。做了很多研究,但坚持了下来。

从我的SQL日期开始:   连接语句(即获取句柄,我已经使用neo4j)   将SQL语句发送到数据库,(在这种情况下,它将是密码)   获取光标并处理结果(我假设处理Jason)

我想举例:

Connect to the database (local and remote)
Show sample cypher commands to fetch data (movie dtabase)
How to store returned results in the javascript program 

如果可能的话,提供Node,HTML,Javascript的简短说明,即javascript进入app.js,并且有index.htnl引用app.js.我是否必须使用Node才能使用Javascript访问neo4j?

由于 玛蒂

2 个答案:

答案 0 :(得分:1)

查看官方Neo4j Driver for Javascript。该驱动程序可以与node.js一起使用,还有一个在浏览器中运行的版本。

repo的自述文件包含完整文档和示例项目的链接。

答案 1 :(得分:0)

AS @cybersam告诉您,您应该使用neo4j-javascript-driver

您可以在此处找到示例应用:https://github.com/neo4j-examples/movies-javascript-bolt

这是关于如何执行连接,查询和解析结果的片段:

// Create a driver instance, for the user neo4j with password neo4j.
// It should be enough to have a single driver per database per application.
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));

// Create a session to run Cypher statements in.
// Note: Always make sure to close sessions when you are done using them!
var session = driver.session();

// the Promise way, where the complete result is collected before we act on it:
session
  .run('MERGE (james:Person {name : {nameParam} }) RETURN james.name AS name', {nameParam: 'James'})
  .then(function (result) {
    result.records.forEach(function (record) {
      console.log(record.get('name'));
    });
    session.close();
  })
  .catch(function (error) {
    console.log(error);
  });

// Close the driver when application exits.
// This closes all used network connections.
driver.close();

此外,您还可以查看 GRAND 堆栈:http://grandstack.io/ 它是基于React,Neo4j和GraphQl(与Apollo)构建Web应用程序的堆栈。