Cargojs is an API for OrientDB operations build on top of Express.
Cargojs support few amount of operations including BREAD at the moment and build using Orientjs as main driver.
- Browse
- Read
- Edit
- Add
- Delete
- Delete-All
- Count
- Query
- Map
- Add
- Remove
- By RID
- Get
- Update
- Delete
Install via npm.
$ npm install cargojs
var Cargo = require('cargojs');
var configuration = {
host: 'localhost',
port: 2424,
user: 'root',
password: 'root',
database: 'sample'
};
app.use(Cargo.express(configuration, {
sync: Cargo.sync.CREATEOREXISTS, // Create the database from meta data
define: function (db, models) {
models.User = db.define("User", {
'name': Cargo.types.STRING,
'age': Cargo.types.INTEGER
});
//more class models....
}
}));
exports.browseUsers = function(req, res) {
req.models.user.browse({
'status': 'active'
}).then(function(users)) {
console.log(users);
},
function(error) {
console.error(error)
});
};
exports.readUser = function(req, res) {
req.models.user.read({
'status': 'active'
}).then(function(user)) {
console.log(user);
},
function(error) {
console.error(error)
});
};
exports.editUser = function(req, res) {
req.models.user.set({
'name': 'Ryan'
}).edit({
'status': 'active'
}).then(function(user)) {
console.log(user);
},
function(error) {
console.error(error)
});
};
exports.addUser = function(req, res) {
req.models.user.add({
'name': 'Ryan',
'lastName': 'Cooper',
'status': 'active'
}).then(function(user)) {
console.log(user);
},
function(error) {
console.error(error);
});
};
exports.deleteUser = function(req, res) {
req.models.user.delete({
'name': 'Ryan'
}).then(function(user)) {
console.log(user);
},
function(error) {
console.error(error);
});
};
exports.deleteAllUser = function(req, res) {
req.models.user.deleteAll({
'name': 'Ryan'
}).then(function(user)) {
console.log(user);
},
function(error) {
console.error(error);
});
};
exports.countUsers = function(req, res) {
req.models.user.count().then(function(total)) {
console.log(total);
},
function(error) {
console.error(error);
});
};
exports.linkUsers = function(req, res) {
var client = req.cargo.RID('#1:5');
var link = req.cargo.RID('#2:3');
req.models.user.addList(client).map({
'project': link
}).then(function(updatedCount)) {
console.log(updatedCount);
},
function(error) {
console.error(error);
});
};
exports.linkUsers = function(req, res) {
var client = req.cargo.RID('#1:5');
var link = req.cargo.RID('#2:3');
req.models.user.removeList(client).map({
'project': link
}).then(function(updatedCount)) {
console.log(updatedCount);
},
function(error) {
console.error(error);
});
};
exports.queryUsers = function(req, res) {
var sql = 'SELECT * FROM User'
req.models.user.query(sql).then(function(result)) {
console.log(result);
},
function(error) {
console.error(error);
});
};
exports.selectColumnsUsers = function(req, res) {
req.models.user.select('name, lastName').browse({
'status': 'active'
}).then(function(users)) {
console.log(users);
},
function(error) {
console.error(error)
});
};
exports.limitUsers = function(req, res) {
req.models.user.limit(5).browse({
'status': 'active'
}).then(function(users)) {
console.log(users);
},
function(error) {
console.error(error)
});
};
exports.getUserbyRID = function(req, res) {
req.record.get('#12:1').then(function(user)) {
console.log(user);
},
function(error) {
console.error(error)
});
};
exports.updateUserbyRID = function(req, res) {
req.record.RID('#12:1').update({
name: 'Ryan'
}).then(function(use)) {
console.log(user);
},
function(error) {
console.error(error)
});
};
exports.deleteUserbyRID = function(req, res) {
req.record.delete('#12:1').then(function(user)) {
console.log(user);
},
function(error) {
console.error(error)
});
};
0.5.6
Want to contribute? Great! Pull-requests are welcome
- Remove Orientjs and be standalone.
- Add more operations like Create classes | Add properties etc...
- Custom operations.