-
-
Save myndzi/e46f024ed4fb16286a4cbed191c2cf8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readFileAsync = Promise.promisify(fs.readFile, fs); | |
module.exports = { | |
init: function(env) { | |
if (!env) throw new Error(ERRENV); | |
var self = this; | |
if (!env.proto) env.proto = 'http'; | |
self.env = env; | |
self.url = str.url(env); | |
self.db = new neo.GraphDatabase(self.url); | |
self.cypherAsync = Promise.promisify(self.db.cypher, self.db); | |
return Promise.try(function () { | |
return self.get_thing(); // i don't know what this query represents, rename | |
}).then(function (r) { | |
if (r.length > 0) { return; } | |
return self.script(); | |
}).tap(function () { | |
console.log('Database initialized'); | |
}); | |
}, | |
get_thing: function() { | |
var fmt = 'match (n:{0} {type: "{0}"}) return n'; | |
var q = str.tok(fmt, ['Root:Schema']); | |
return this.send(q); | |
}, | |
script: function(fn) { | |
var self = this; | |
return Promise.try(function () { | |
return readFileAsync(fn, 'utf8'); | |
}).then(function (data) { | |
return data.split('\n'); | |
}).each(function (q) { | |
return self.send(q); | |
}); | |
}, | |
send: function (q) { | |
return this.cypherAsync({ query: q }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment