Skip to content

Commit e035a8a

Browse files
authored
Updates code to assume Neo4j Version 5 and remove deprecated function usage
1 parent 3ae33c4 commit e035a8a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: src/neo4jApi.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
require('file-loader?name=[name].[ext]!../node_modules/neo4j-driver/lib/browser/neo4j-web.min.js');
21
const Movie = require('./models/Movie');
32
const MovieCast = require('./models/MovieCast');
43
const _ = require('lodash');
54

6-
const neo4j = window.neo4j;
5+
const neo4j = require('neo4j-driver');
76
const neo4jUri = process.env.NEO4J_URI;
87
let neo4jVersion = process.env.NEO4J_VERSION;
98
if (neo4jVersion === '') {
10-
// assume Neo4j 4 by default
11-
neo4jVersion = '4';
9+
// assume Neo4j 5 by default
10+
neo4jVersion = '5';
1211
}
1312
let database = process.env.NEO4J_DATABASE;
14-
if (!neo4jVersion.startsWith("4")) {
13+
if (!neo4jVersion.startsWith("4") || !neo4jVersion.startsWith("5")) {
1514
database = null;
1615
}
1716
const driver = neo4j.driver(
@@ -23,7 +22,7 @@ console.log(`Database running at ${neo4jUri}`)
2322

2423
function searchMovies(title) {
2524
const session = driver.session({database: database});
26-
return session.readTransaction((tx) =>
25+
return session.executeRead((tx) =>
2726
tx.run('MATCH (movie:Movie) \
2827
WHERE toLower(movie.title) CONTAINS toLower($title) \
2928
RETURN movie',
@@ -44,7 +43,7 @@ function searchMovies(title) {
4443

4544
function getMovie(title) {
4645
const session = driver.session({database: database});
47-
return session.readTransaction((tx) =>
46+
return session.executeRead((tx) =>
4847
tx.run("MATCH (movie:Movie {title:$title}) \
4948
OPTIONAL MATCH (movie)<-[r]-(person:Person) \
5049
RETURN movie.title AS title, \
@@ -68,7 +67,7 @@ function getMovie(title) {
6867

6968
function voteInMovie(title) {
7069
const session = driver.session({ database: database });
71-
return session.writeTransaction((tx) =>
70+
return session.executeWrite((tx) =>
7271
tx.run("MATCH (m:Movie {title: $title}) \
7372
SET m.votes = coalesce(m.votes, 0) + 1", { title }))
7473
.then(result => {
@@ -81,7 +80,7 @@ function voteInMovie(title) {
8180

8281
function getGraph() {
8382
const session = driver.session({database: database});
84-
return session.readTransaction((tx) =>
83+
return session.executeRead((tx) =>
8584
tx.run('MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) \
8685
RETURN m.title AS movie, collect(a.name) AS cast \
8786
LIMIT $limit', {limit: neo4j.int(100)}))

0 commit comments

Comments
 (0)