Published
Edited
Apr 6, 2021
Insert cell
Insert cell
Insert cell
neo4j = {
// const neo4j = await require('neo4j-driver@1/lib/browser/neo4j-web.js');
// const neo4j = await require('https://cdn.jsdelivr.net/npm/neo4j-driver@4.1/lib/browser/neo4j-web.js');

const neo4j = await require('neo4j-driver');
return neo4j;
}
Insert cell
Insert cell
driver = neo4j.driver(
"bolt://localhost:7687",
neo4j.auth.basic("neo4j", "")
)
Insert cell
Insert cell
persons = {
const session = driver.session();
let results;

await session
.run('MATCH (n) return n')
.then(r => {
results = r.records.map(d => d.toObject());
session.close();
})
.catch(error => {
results = [];
console.log(error);
});

return results;
}
Insert cell
movies = {
const session = driver.session();
let results;

await session
.run('MATCH (n) return n')
.then(r => {
results = r.records.map(d => d.toObject());
session.close();
})
.catch(error => {
results = [];
console.log(error);
});

return results;
}
Insert cell
roles = {
const session = driver.session();
let results;

await session
.run('MATCH p = (:Person)-[:ACTED_IN]->(:Movie) return p')
.then(r => {
results = r.records.map(d => {
let s = d.toObject().p.segments[0]
return {source: s.start.properties.name, target: s.end.properties.title, roles: s.relationship.properties.roles}
});
session.close();
})
.catch(error => {
results = [];
console.log(error);
});

return results
}
Insert cell
Insert cell
viewof cypherRunner = {
const mainDiv = html`<div><div>`;
const editorDiv = html`<div style="border: 1px solid rgb(0, 0, 0);height: 200px;"></div>`;
const runButton = html`<button>Run Query</button>`;

mainDiv.append(editorDiv);
mainDiv.append(runButton);

mainDiv.value = [];

yield mainDiv;

let editor = CodeMirror(editorDiv, { mode: "application/x-cypher-query" });

editor.setValue(`MATCH (n) return n`);
editor.setSize(width - 20, 200);

runButton.onclick = e => {
const session = driver.session();
session
.run(editor.getValue())
.then(r => {
mainDiv.value = r.records.map(d => d.toObject());
mainDiv.dispatchEvent(new CustomEvent("input"));
session.close();
})
.catch(error => {
mainDiv.value = error;
mainDiv.dispatchEvent(new CustomEvent("input"));
});
};

return mainDiv;
}
Insert cell
cypherRunner
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart
Insert cell
Insert cell
Insert cell
Insert cell
import {select, text, number, password as passwordInput} from "@jashkenas/inputs"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
npm i @observablehq/runtime
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more