This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mongo DB features to the framework
- Loading branch information
Showing
12 changed files
with
169 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"", | ||
"\\features", | ||
"\\features\\event" | ||
], | ||
"SelectedNode": "\\rest_factory.js", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
// Use IntelliSense to learn about possible Node.js debug attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Grunt task", | ||
"program": "${workspaceRoot}/node_modules/grunt-cli/bin/grunt" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach by Process ID", | ||
"processId": "${command:PickProcess}" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach", | ||
"port": 5858 | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "node_modules\\grunt-cli\\bin\\grunt", | ||
"stopOnEntry": true, | ||
"cwd": "${workspaceRoot}" | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
var Db = require('mongodb').Db; | ||
var Connection = require('mongodb').Connection; | ||
var Server = require('mongodb').Server; | ||
var BSON = require('mongodb').BSON; | ||
var ObjectID = require('mongodb').ObjectID; | ||
|
||
dataFactory = function(db, host, port) { | ||
this.db= new Db(db, new Server(host, port, {safe: false}, {auto_reconnect: true}, {})); | ||
this.db.open(function(){}); | ||
}; | ||
|
||
|
||
dataFactory.prototype.getCollection= function(collection, callback) { | ||
this.db.collection(collection, function(error, data_collection) { | ||
if( error ) callback(error); | ||
else callback(null, data_collection); | ||
}); | ||
}; | ||
|
||
//find all datas | ||
dataFactory.prototype.findAll = function(callback) { | ||
this.getCollection(function(error, data_collection) { | ||
if( error ) callback(error) | ||
else { | ||
data_collection.find().toArray(function(error, results) { | ||
if( error ) callback(error) | ||
else callback(null, results) | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
//find an data by ID | ||
dataFactory.prototype.findById = function(id, callback) { | ||
this.getCollection(function(error, data_collection) { | ||
if( error ) callback(error) | ||
else { | ||
data_collection.findOne({_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(id)}, function(error, result) { | ||
if( error ) callback(error) | ||
else callback(null, result) | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
|
||
//save new data | ||
dataFactory.prototype.save = function(collection, callback) { | ||
this.getCollection(function(error, data_collection) { | ||
if( error ) callback(error) | ||
else { | ||
if( typeof(collection.length)=="undefined") | ||
collection = [collection]; | ||
|
||
for( var i =0;i< datas.length;i++ ) { | ||
data = collection[i]; | ||
data.created_at = new Date(); | ||
} | ||
|
||
data_collection.insert(datas, function() { | ||
callback(null, collection); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
// update an data | ||
dataFactory.prototype.update = function(dataId, collection, callback) { | ||
this.getCollection(function(error, data_collection) { | ||
if( error ) callback(error); | ||
else { | ||
data_collection.update( | ||
{_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(dataId)}, | ||
datas, | ||
function(error, collection) { | ||
if(error) callback(error); | ||
else callback(null, collection) | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
//delete data | ||
dataFactory.prototype.delete = function(dataId, callback) { | ||
this.getCollection(function(error, data_collection) { | ||
if(error) callback(error); | ||
else { | ||
data_collection.remove( | ||
{_id: data_collection.db.bson_serializer.ObjectID.createFromHexString(dataId)}, | ||
function(error, data){ | ||
if(error) callback(error); | ||
else callback(null, data) | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
exports.dataFactory = dataFactory; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
var helloWorld = function helloWorld(callback){ | ||
|
||
self = this; | ||
|
||
this.message = function(name){ | ||
console('Hello '+name); | ||
} | ||
|
||
module.exports.helloWorld = helloWorld; | ||
} |
This file contains 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