Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Add database option to inferSchema config
Browse files Browse the repository at this point in the history
Fix #419
  • Loading branch information
johnymontana committed Apr 28, 2020
1 parent 86b3d57 commit 69b4c8e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/neo4j-schema/Neo4jSchemaTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import neo4jTypes from './types';
const extractRelationshipType = relTypeName =>
relTypeName.substring(2, relTypeName.length - 1);

const withSession = (driver, f) => {
const s = driver.session();
const withSession = (driver, database, f) => {
let s;
if (database) {
s = driver.session({ database });
} else {
s = driver.session();
}

return f(s).finally(() => s.close());
};
Expand All @@ -29,6 +34,7 @@ export default class Neo4jSchemaTree {
this.driver = driver;
this.nodes = {};
this.rels = {};
this.config = config;
}

toJSON() {
Expand All @@ -52,8 +58,8 @@ export default class Neo4jSchemaTree {
console.log('Initializing your Neo4j Schema');
console.log('This may take a few moments depending on the size of your DB');
return Promise.all([
withSession(this.driver, nodeTypeProperties),
withSession(this.driver, relTypeProperties)
withSession(this.driver, this.config.database, nodeTypeProperties),
withSession(this.driver, this.config.database, relTypeProperties)
])
.then(([nodeTypes, relTypes]) => this._populate(nodeTypes, relTypes))
.then(() => this._populateRelationshipLinkTypes())
Expand All @@ -72,7 +78,7 @@ export default class Neo4jSchemaTree {
RETURN distinct(labels(n)) as from, labels(m) as to
`;

return withSession(this.driver, s =>
return withSession(this.driver, this.config.database, s =>
s.run(q).then(results => results.records.map(r => r.toObject()))
).then(rows => {
this.getRel(okapiId).relType = extractRelationshipType(okapiId);
Expand Down

0 comments on commit 69b4c8e

Please sign in to comment.