Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titarenko/node-qstorage
Partial wrapper around MongoDB API which employs promises instead of callbacks.
https://github.com/titarenko/node-qstorage
Last synced: about 1 month ago
JSON representation
Partial wrapper around MongoDB API which employs promises instead of callbacks.
- Host: GitHub
- URL: https://github.com/titarenko/node-qstorage
- Owner: titarenko
- Created: 2014-01-01T11:33:01.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-03T21:34:13.000Z (about 11 years ago)
- Last Synced: 2024-11-24T13:07:41.428Z (about 1 month ago)
- Language: CoffeeScript
- Homepage:
- Size: 129 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# qstorage
Partial wrapper around [MongoDB API](https://github.com/mongodb/node-mongodb-native) which employs [promises](https://github.com/kriskowal/q) instead of callbacks.
[![Build Status](https://secure.travis-ci.org/titarenko/node-qstorage.png?branch=master)](https://travis-ci.org/titarenko/node-qstorage) [![Coverage Status](https://coveralls.io/repos/titarenko/node-qstorage/badge.png)](https://coveralls.io/r/titarenko/node-qstorage)
[![NPM](https://nodei.co/npm/qstorage.png?downloads=true&stars=true)](https://nodei.co/npm/qstorage/)
## Usage
By default `qstorage` lazily connects to MongoDB instance using connection string provided via `CONNECTION_STRING` environment variable.
*If you need to provide connection string via API call, these details will be discussed below.*
So, everything you need, is start directly from inserting, querying and updating your documents!
```coffee
storage = require "qstorage"storage
.insert("mydocs", prop1: "val1", prop2: 2)
.then(-> storage.find("mydocs", prop1: "val1"))
.then((doc) -> storage.update("mydocs", {prop1: doc.prop1}, {$set: prop2: 3}))
.then(-> storage.drop("mydocs"))
.catch((error) -> console.log error)
.done(-> console.log "Everything is OK!")
```As you may noticed, `qstorage` API follows promise pattern and for this purpose it uses [Q](https://github.com/kriskowal/q) library.
### Connection
If you want to explicitly connect to DB other than specified via environment variable, you can use `connection.connect` method.
```coffee
connection = require "qstorage/connection"connection
.connect("mongodb://myinstance")
.catch((error) -> console.log error)
.done(-> console.log "Hooray!")
```## License
MIT