tpc-dataservice
v0.0.9
Published
Data Service
Downloads
6
Readme
A simple MongoDB based Data Service utility.
Installation
npm install tpc-dataservice --save
Configuration
Setup the Environment
Set the environment variables
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017
SCHEMA_FILE=./resources/service.schema.js
SCHEMA_NAME=users
Usage
The usage of the data service utility is pretty straight forward.
var dataService=require('tpc-dataservice');
//Connect to a database
dataService.connect(function(result){
console.log(JSON.stringify(result));
});
//To get all entries from a collection
dataService.all(function(result){
console.log(JSON.stringify(result));
});
//To create a new entry
var entry={first_name:'John', last_name:'Smith'};
dataService.create(entry, function(result){
console.log(JSON.stringify(result));
});
//To read an entry
var id=4815162342;
dataService.read(id, function(result){
console.log(JSON.stringify(result));
});
//To update an entry
var id=4815162342;
var updates={first_name:'John', last_name:'Doe'};
dataService.update(id, udpates, function(result){
console.log(JSON.stringify(result));
});
//To remove an entry
var id=4815162342;
dataService.delete(id, function(result){
console.log(JSON.stringify(result));
});
That's all folks!