-
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.
- Loading branch information
0 parents
commit 986d2b5
Showing
25 changed files
with
720 additions
and
0 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
.DS_Store | |||
.monitor | |||
.*.swp | |||
.nodemonignore | |||
releases | |||
*.log | |||
*.err | |||
fleet.json | |||
public/browserify | |||
bin/*.json | |||
.bin | |||
build | |||
compile | |||
.lock-wscript | |||
**/examples* | |||
node_modules |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
{ | |||
"launchers": { | |||
"node": { | |||
"command": "npm test", | |||
"protocol": "tap" | |||
} | |||
}, | |||
"src_files": [ | |||
"./**/*.js" | |||
], | |||
"launch_in_dev": ["node"] | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
language: node_js | |||
node_js: | |||
- 0.8 | |||
- 0.9 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
Copyright (c) 2012 Raynos. | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
# mongo-client | |||
|
|||
[![build status][1]][2] | |||
|
|||
No bullshit mongo wrapper | |||
|
|||
## Example | |||
|
|||
```js | |||
var uuid = require("node-uuid") | |||
var assert = require("assert") | |||
var fold = require("reducers/fold") | |||
var expand = require("reducers/expand") | |||
|
|||
var mongo = require("mongo-client") | |||
var insert = require("mongo-client/insert") | |||
var findOne = require("mongo-client/findOne") | |||
var close = require("mongo-client/close") | |||
|
|||
var client = mongo("mongodb://localhost:27017/mongo-client-example") | |||
var collection = client(uuid()) | |||
|
|||
var insertResult = insert(collection, { | |||
hello: "world" | |||
}) | |||
|
|||
var findResult = expand(insertResult, function (item) { | |||
assert.equal(item.hello, "world") | |||
return findOne(collection, { | |||
hello: "world" | |||
}) | |||
}) | |||
|
|||
fold(findResult, function (value) { | |||
assert.equal(value.hello, "world") | |||
console.log("value", value) | |||
close(collection) | |||
}) | |||
``` | |||
|
|||
## Commands | |||
|
|||
Supports | |||
|
|||
- update DONE | |||
- insert DONE | |||
- remove DONE | |||
- findAndModify | |||
- findAndRemove | |||
- findOne DONE | |||
- find DONE | |||
- mapReduce DONE | |||
|
|||
## Installation | |||
|
|||
`npm install mongo-client` | |||
|
|||
## Contributors | |||
|
|||
- Raynos | |||
|
|||
## MIT Licenced | |||
|
|||
|
|||
[1]: https://secure.travis-ci.org/Raynos/mongo-client.png | |||
[2]: http://travis-ci.org/Raynos/mongo-client |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
var fold = require("reducers/fold") | |||
|
|||
module.exports = close | |||
|
|||
function close(collection, callback) { | |||
return fold(collection, function (collection) { | |||
if (collection.close) { | |||
return collection.close(callback) | |||
} | |||
|
|||
collection.db.close(callback) | |||
}) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
var reduce = require("reducible/reduce") | |||
var end = require("reducible/end") | |||
var isReduced = require("reducible/is-reduced") | |||
var Cursor = require("mongodb").Cursor | |||
|
|||
reduce.define(Cursor, function (cursor, next, initial) { | |||
var result = initial | |||
|
|||
recurse() | |||
|
|||
function recurse() { | |||
cursor.nextObject(function (error, value) { | |||
if (error) { | |||
return next(error, result) | |||
} | |||
|
|||
if (value === null) { | |||
return next(end, result) | |||
} | |||
|
|||
result = next(value, result) | |||
|
|||
if (isReduced(result)) { | |||
cursor.close(function () { | |||
next(end, result.value) | |||
}) | |||
} else { | |||
recurse() | |||
} | |||
}) | |||
} | |||
}) |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
var uuid = require("node-uuid") | |||
var assert = require("assert") | |||
var fold = require("reducers/fold") | |||
var expand = require("reducers/expand") | |||
|
|||
var mongo = require("..") | |||
var insert = require("../insert") | |||
var findOne = require("../findOne") | |||
var close = require("../close") | |||
|
|||
var client = mongo("mongodb://localhost:27017/mongo-client-example") | |||
var collection = client(uuid()) | |||
|
|||
var insertResult = insert(collection, { | |||
hello: "world" | |||
}) | |||
|
|||
var findResult = expand(insertResult, function (item) { | |||
assert.equal(item.hello, "world") | |||
return findOne(collection, { | |||
hello: "world" | |||
}) | |||
}) | |||
|
|||
fold(findResult, function (value) { | |||
assert.equal(value.hello, "world") | |||
console.log("value", value) | |||
close(collection) | |||
}) |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
var expand = require("reducers/expand") | |||
var callback = require("callback-reduce") | |||
|
|||
var cursor = require("./cursor") | |||
|
|||
module.exports = find | |||
|
|||
function find(collection, selector, options) { | |||
return expand(collection, function (collection) { | |||
return collection.find(selector || {}, options || {}) | |||
}) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
var take = require("reducers/take") | |||
var concat = require("reducers/concat") | |||
var find = require("./find") | |||
|
|||
module.exports = findOne | |||
|
|||
function findOne(collection, selector, options) { | |||
var items = find(collection, selector, options) | |||
|
|||
return take(concat(items, [null]), 1) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
var mongodb = require("mongodb") | |||
var map = require("reducers/map") | |||
var fold = require("reducers/fold") | |||
var callback = require("callback-reduce") | |||
var cache = require("cache-reduce") | |||
var MongoClient = mongodb.MongoClient | |||
|
|||
module.exports = mongo | |||
|
|||
function mongo(uri, options) { | |||
var mongoClient = cache(callback(MongoClient.connect, uri, options || {})) | |||
|
|||
return client | |||
|
|||
function client(collectionName) { | |||
return map(mongoClient, function (db) { | |||
return db.collection(collectionName) | |||
}) | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
var expand = require("reducers/expand") | |||
var callback = require("callback-reduce") | |||
|
|||
module.exports = insert | |||
|
|||
function insert(collection, doc, options) { | |||
return expand(collection, function (collection) { | |||
return callback.call(collection, collection.insert | |||
, doc, options || {}) | |||
}) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
var callback = require("callback-reduce") | |||
var expand = require("reducers/expand") | |||
|
|||
module.exports = mapReduce | |||
|
|||
function mapReduce(collection, map, reduce, options) { | |||
return expand(collection, function (collection) { | |||
return callback.call(collection, collection.mapReduce | |||
, map, reduce, options || {}) | |||
}) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
{ | |||
"name": "mongo-client", | |||
"version": "0.1.0", | |||
"description": "No bullshit mongo wrapper", | |||
"keywords": [], | |||
"author": "Raynos <raynos2@gmail.com>", | |||
"repository": "git://github.com/Raynos/mongo-client.git", | |||
"main": "index", | |||
"homepage": "https://github.com/Raynos/mongo-client", | |||
"contributors": [ | |||
{ | |||
"name": "Jake Verbaten" | |||
} | |||
], | |||
"bugs": { | |||
"url": "https://github.com/Raynos/mongo-client/issues", | |||
"email": "raynos2@gmail.com" | |||
}, | |||
"dependencies": { | |||
"testem": "~0.2.52", | |||
"reducers": "~2.0.0", | |||
"mongodb": "~1.2.7", | |||
"callback-reduce": "~1.0.0", | |||
"reducible": "~1.0.5", | |||
"cache-reduce": "~0.1.1" | |||
}, | |||
"devDependencies": { | |||
"tape": "0.1.5", | |||
"browserify": "https://github.com/raynos/node-browserify/tarball/master", | |||
"testem": "0.2.52", | |||
"node-uuid": "~1.4.0" | |||
}, | |||
"licenses": [ | |||
{ | |||
"type": "MIT", | |||
"url": "http://github.com/Raynos/mongo-client/raw/master/LICENSE" | |||
} | |||
], | |||
"scripts": { | |||
"test": "node ./test", | |||
"build": "browserify test/index.js -o test/bundle.js", | |||
"testem": "testem", | |||
"postinstall": "npm dedup" | |||
}, | |||
"testling": { | |||
"files": "test/*.js", | |||
"browsers": { | |||
"ie": [ | |||
"8", | |||
"9", | |||
"10" | |||
], | |||
"firefox": [ | |||
"16", | |||
"17", | |||
"nightly" | |||
], | |||
"chrome": [ | |||
"22", | |||
"23", | |||
"canary" | |||
], | |||
"opera": [ | |||
"12", | |||
"next" | |||
], | |||
"safari": [ | |||
"5.1" | |||
] | |||
} | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
var expand = require("reducers/expand") | |||
var callback = require("callback-reduce") | |||
|
|||
module.exports = remove | |||
|
|||
function remove(collection, selector, options) { | |||
return expand(collection, function (collection) { | |||
return callback.call(collection, collection.remove | |||
, selector, options) | |||
}) | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
var test = require("tape") | |||
var mongo = require("..") | |||
var close = require("../close") | |||
|
|||
test("mongo is a function", function (assert) { | |||
assert.equal(typeof mongo, "function") | |||
assert.end() | |||
}) | |||
|
|||
test("mongo returns a function", function (assert) { | |||
var client = mongo("mongodb://localhost:27017/mongo-client-test") | |||
assert.equal(typeof client, "function") | |||
close(client("tests"), function (err) { | |||
assert.ifError(err) | |||
assert.end() | |||
}) | |||
}) | |||
|
|||
test("client returns a collection", function (assert) { | |||
var client = mongo("mongodb://localhost:27017/mongo-client-test") | |||
var collection = client("tests") | |||
|
|||
assert.equal(typeof collection, "object") | |||
close(collection, function (err) { | |||
assert.ifError(err) | |||
assert.end() | |||
}) | |||
}) |
Oops, something went wrong.