This is a waterline ORM adapter which connects SailsJS app to OrientDB data store. It implements basic CRUD operations on OrientDB using its Binary protocol that is exposed through Oriento.
This version of the adapter is for the v0.10 release of Sails / Waterline.
Install from NPM.
# In your app:
$ npm install sails-orientdb-binaryAdd the OrientDB config to the config/adapters.js file. Basic options:
module.exports.adapters = {
'default': 'orientdb-bin',
orientdb-bin: {
module : 'sails-orientdb-binary',
host : 'localhost',
port : 3306,
user : 'username',
password : 'password',
database : 'OrientDB Database Name'
}
};This adapter is based on [Oriento] (https://github.com/codemix/oriento)) which uses the binary protocol to access OrientDB. Using this adapter you can do below oprations on OrientDB classes.
Example usage: Below example find all those User records where id (in OrientDB its @rid - primary key) is #5:3 and name attribute is 'mike'
User.find({
where: {
id: '#5:3',
name: 'mike'
}
})
.exec(function (err, result) {
if (err) {
console.log("Something went wrong");
} else {
console.log("Returned result from server:");
console.log(result);
res.json(result);
}
});Example usage: Below example inserts new record with four attributes / fields in User collection
User.create({
name: 'Mike',
firstName: 'Mike',
lastName: 'Tyson',
mobieNumber: '1-805-345-xxx'
})
.exec(function (err, result) {
if (err) {
console.log("Something went wrong");
} else {
console.log("Record added !");
res.json(result);
}
});Example usage: Below example will update lastName and mobileNumber attributes of max 5 records where firstName starts with 'Mike' and email is 'mike@tyson.com'
User.update(
{
where:{
firstName: {
'LIKE': 'Mike'
},
email: 'mike@tyson.com'
},
limit: 5
},
{
lastName: 'Luther',
mobileNumber: '1-304-555-xxx'
}
)
.exec(function (err, result) {
if (err) {
console.log("Something went wrong");
} else {
console.log("Record updated !");
res.json(result);
}
});Example usage: Below example will delete max 5 records where firstName starts with 'Mike' and email is 'mike@tyson.com'
User.destroy(
{
where:{
firstName: {
'LIKE': 'Mike'
},
email: 'mike@tyson.com'
},
limit: 5
}
)
.exec(function (err, result) {
console.log("deleted !");
console.log(result);
res.json(result);
});callDBFunction: OrientDB allows you to write function in javascript or SQL which work very similar to stored procedures. We can call such defined function using callDBFunction method of this adapter.
Example usage: Below example calls the defined OrientDB functions getAllStates() with parameter 'India'.
User.callDBFunction(
{
funcName:"getAllStates",
params: {
countryName: "India"
}
},
function (err, result) {
console.log("Function called !");
console.log(result);
res.json(result);
}
);Waterline is a brand new kind of storage and retrieval engine.
It provides a uniform API for accessing stuff from different kinds of databases, protocols, and 3rd party APIs. That means you write the same code to get users, whether they live in MySQL, OrientDB, LDAP, MongoDB, or Facebook.
MIT © 2014 Gaurav Dhiman, TechZulla & contributors
Sails is free and open-source MVC framework based on [NodeJS] (http://nodejs.org/). It is licensed under the MIT License. OrientDB is free and open-source under the Apache 2. As its open-source, you can get its sources [here] (https://github.com/orientechnologies/orientdb)
