Closed ekkis closed 8 years ago
@ekkis were you able to get a solution...?
I did. it was a long journey. here's what I ended up writing to accomplish this:
var fs = require('fs');
var neo = require('neo4j');
var Promise = require('bluebird');
var readFileAsync = Promise.promisify(
fs.readFile, { context: fs }
);
init: function(env, opts) {
self.cypherAsync = Promise.promisify(
self.db.cypher, { context: self.db }
);
},
sendFile: function(fn) {
var self = this;
return Promise.try(function () {
return readFileAsync(fn, 'utf8');
}).then(function (data) {
return data.split('\n');
}).each(function (q) {
q = q.replace(/^\/\/.*/, '');
if (q.match('^\s*$')) return;
return self.cypherAsync({ query: q });
}).then(function() {
return true;
});
},
which can be called like this:
.sendFile('/tmp/myscript.cph').then(() => {
console.log('loaded');
});
thank you
You can simply use neo4j-shell with -file command.
.bin/neo4j-shell -file filepath -path your_databasefile_path -v
I have a file with a bunch of cypher. I tried sending it to the server but it pukes with "neo4j.ClientError: [Neo.ClientError.Statement.InvalidSyntax] Expected exactly one statement per query but got: 7"
is there a method I can use to give it a file name and have it run its contents?
alternatively, can anyone suggest how I could run all the lines individually (each with its own callback) and only once it's complete I could print a message? it seems I may need promises for this but I'm hoping for a better approach