Comparing version
@@ -25,2 +25,24 @@ /*! | ||
/** | ||
* bind extend functions to collection | ||
* | ||
* e.g. | ||
* | ||
* db.bind('article').bind({ | ||
* getPostByAuthor: function(id, callback) { | ||
* this.findOne({author_id: id}, callback); | ||
* } | ||
* }); | ||
* | ||
*/ | ||
SkinCollection.prototype.bind = function(extendObject) { | ||
for(var key in extendObject) { | ||
if(typeof extendObject[key] == 'function') { | ||
this[key] = extendObject[key].bind(this); | ||
} else { | ||
this[key] = extendObject[key]; | ||
} | ||
} | ||
} | ||
SkinCollection.prototype._open = function(callback) { | ||
@@ -27,0 +49,0 @@ var collection_args = this._collection_args.concat([callback]); |
{ | ||
"name": "mongoskin", | ||
"description": "The future layer above node-mongodb-native", | ||
"version": "1.3.20-alpha", | ||
"version": "1.3.20", | ||
"author": "Gui Lin <guileen@gmail.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/kissjs/node-mongoskin", |
@@ -5,15 +5,7 @@ # mongoskin | ||
[](https://david-dm.org/kissjs/node-mongoskin) | ||
[](https://coveralls.io/r/kissjs/node-mongoskin?branch=1.3.20) | ||
[](https://coveralls.io/r/kissjs/node-mongoskin?branch=master) | ||
[](http://badge.fury.io/js/mongoskin) | ||
 | ||
[](https://nodei.co/npm/mongoskin/) | ||
This project is a wrapper for [node-mongodb-native](https://github.com/mongodb/node-mongodb-native). | ||
The base API is same at the node-mongodb-native, you may want to familiarise yourself with the [node-mongodb-native documentation](http://mongodb.github.com/node-mongodb-native/) first. | ||
## NOTE!! mongoskin API change from 1.3.20 | ||
Since node-mongodb-native has change a lot of API, mongoskin redesign from 1.3.20. The version number keep same with node-mongodb-native. And the API appearence is also keep same with node-mongodb-native | ||
Install | ||
@@ -33,5 +25,3 @@ ======== | ||
var mongo = require('mongoskin'); | ||
var MongoClient = mongo.MongoClient; | ||
var db = MongoClient.connect("mongodb://localhost:27017/integration_tests", {native_parser:true}); | ||
var db = mongo.db("mongodb://localhost:27017/integration_tests", {native_parser:true}); | ||
db.bind('article'); | ||
@@ -63,7 +53,24 @@ db.article.find().toArray(function(err, items) { | ||
Model helper: | ||
```js | ||
var mongo = require('mongoskin'); | ||
var db = mongo.db("mongodb://localhost:27017/integration_tests", {native_parser:true}); | ||
db.bind('article').bind({ | ||
getByAuthor: function(author_id, callback) { | ||
this.findOne({author_id: author_id}, callback); | ||
} | ||
}); | ||
db.article.getByAuthor(author_id, function(err, article) { | ||
console.log(article); | ||
}); | ||
``` | ||
## Origin API part | ||
For detail API reference see [node mongodb API](http://mongodb.github.io/node-mongodb-native/). Mongoskin is just change the API call chain. | ||
We make some common use functioin in promise mode, we call it SkinClass of a normal Class. And the API is almost same with official API. | ||
We make some common use functions in promise mode, we call it SkinClass of a normal Class. And the API is almost same with official API. | ||
### module | ||
origin: | ||
@@ -90,6 +97,12 @@ ```js | ||
### MongoClient.connect(...) | ||
returns a `Db` instance | ||
alias origin `MongoClient.connect(..., function(err, db) { .... })` | ||
origin: | ||
```js | ||
MongoClient.connect(..., functioin(err, db) { | ||
MongoClient.connect(..., function(err, db) { | ||
}) | ||
@@ -104,2 +117,8 @@ ``` | ||
### db.collection(..., [callback]) | ||
returns a `Collection` instance | ||
alias origin `db.collection(..., function(err, collection) {....})` | ||
origin: | ||
@@ -109,4 +128,4 @@ | ||
var db = new Db(...); | ||
db.open(functioin(err, db) { | ||
db.collection('myCollection', {strict: true}, functioin(err, myCollection) { | ||
db.open(function(err, db) { | ||
db.collection('myCollection', {strict: true}, function(err, myCollection) { | ||
// myCollection.find() ... | ||
@@ -124,14 +143,2 @@ }); | ||
## Promised methods | ||
### MongoClient.connect(...) | ||
returns a `Db` instance | ||
alias origin `MongoClient.connect(..., function(err, db) { .... })` | ||
### db.collection | ||
returns a `Collection` instance | ||
alias origin `db.collection(..., function(err, collection) {....})` | ||
### collection.find | ||
returns a `Cursor` instance | ||
alias origin `collection.find(..., function(err, cursor) {....})` | ||
## MongoSkin API part | ||
@@ -141,2 +148,14 @@ | ||
alias `MongoClient.connect(...)` | ||
### module.helper.toObjectId(hexStr) | ||
convert `String` to `ObjectID` instance. | ||
### db.bind(name, options) | ||
alias `db[name] = db.collection(name, options)` | ||
```js | ||
db.bind('article') | ||
db.article.find().toArray(function(err, items) { | ||
assert.ok(err == null); | ||
}); | ||
``` | ||
### db.admin(...) | ||
@@ -148,2 +167,4 @@ alias `new Admin(db, ...)` | ||
alias `new GridStore(db, ...)` | ||
### collection.bind(extendObject) | ||
each method of extendObject will be bind to collection. | ||
### collection.findById(id, ...) | ||
@@ -156,3 +177,6 @@ alias `collection.find({_id: toObjectID(id)}, ...)` | ||
## NOTE!! mongoskin API change from 1.3.20 | ||
Since node-mongodb-native has change a lot of API, mongoskin redesign from 1.3.20. The version number keep same with node-mongodb-native. And the API appearence is also keep same with node-mongodb-native | ||
### Removed API from mongoskin 1.3.20 | ||
@@ -159,0 +183,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
709
3.05%0
-100%257
10.3%0
-100%33253
-57.34%30
-3.23%