Skip to content

Instantly share code, notes, and snippets.

@jymcheong
Last active October 16, 2018 03:29
Show Gist options
  • Save jymcheong/f7200eba753f2a13cab8fc495d2c1fcd to your computer and use it in GitHub Desktop.
Save jymcheong/f7200eba753f2a13cab8fc495d2c1fcd to your computer and use it in GitHub Desktop.
OrientJS beta sample
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));
@jymcheong
Copy link
Author

@jymcheong
Copy link
Author

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