Last active
October 16, 2018 03:29
-
-
Save jymcheong/f7200eba753f2a13cab8fc495d2c1fcd to your computer and use it in GitHub Desktop.
OrientJS beta sample
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
const OrientDBClient = require("orientjs").OrientDBClient; | |
var _session, _client, _handle; | |
OrientDBClient.connect({ | |
host: "localhost", | |
port: 2424 | |
}).then(client => { | |
_client = client; | |
client.session({ name: "YOURDB", username: "YOURID", password: "YOURPASSWORD" }) | |
.then(session => { | |
// use the session | |
console.log('session opened') | |
_session = session; | |
_handle = session.liveQuery("select from processcreate").on("data", data => { | |
console.log(data); | |
}); | |
}) | |
}); | |
process.stdin.resume(); //so the program will not close instantly, Ctl+C to clean-up & quit | |
function exitHandler(err) { | |
console.log('cleaning up...') | |
_handle.unsubscribe() | |
_session.close() | |
.then(() =>{ | |
console.log('session closed'); | |
_client.close() | |
.then(() => { | |
console.log('client closed'); | |
process.exit(); | |
}) | |
}) | |
} | |
process.on('exit', exitHandler.bind(null)); | |
process.on('SIGINT', exitHandler.bind(null)); | |
process.on('SIGUSR1', exitHandler.bind(null)); | |
process.on('SIGUSR2', exitHandler.bind(null)); | |
process.on('uncaughtException', exitHandler.bind(null)); |
Need to close sessions & handles, otherwise you will see lots of exceptions at server side console.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://orientdb.com/docs/3.0.x/orientjs/OrientJS-beta.html