Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Irrelon committed Mar 18, 2013
0 parents commit c506878
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
165 changes: 165 additions & 0 deletions .gitignore
@@ -0,0 +1,165 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML



############
## Windows
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Mac crap
.DS_Store

.idea
103 changes: 103 additions & 0 deletions index.js
@@ -0,0 +1,103 @@
var mongodb = require('mongodb');

var mongoease = function (options) {
// Setup the mongo module
this._mongo = {};
this._mongo.Db = require('../../../' + modulePath + 'mongodb').Db;
this._mongo.Connection = require('../../../' + modulePath + 'mongodb').Connection;
this._mongo.Server = require('../../../' + modulePath + 'mongodb').Server;
this._mongo.BSON = this._mongo.Db.bson_serializer;

this._host = options.host;
this._database = options.database;
this._port = options.port;
this._username = options.user;
this._password = options.pass;
};

/**
* Connect to the database with the current settings.
* @param callback
*/
mongoease.prototype.connect = function (callback) {
console.log('Connecting to mongo database "' + this._database + '" @' + this._host + ':' + this._port);

var mongoServer = new this._mongo.Server(
this._host,
parseInt(this._port),
{}
), self = this;

this.client = new this._mongo.Db(
this._database,
mongoServer,
{native_parser: this._nativeParser}
);

this.client.strict = this._strict;

// Open the database connection
this.client.open(function(err, db) {
// If we have a username then authenticate!
if (self._username) {
self.client.authenticate(self._username, self._password, function (err) {
if (err) {
self.log('Error when authenticating with the database!');
//console.log(err);

if (typeof(callback) === 'function') {
callback.apply(self, [err]);
}
} else {
self.log('Connected to mongo DB ok, processing callbacks...');
self._connected.apply(self, [err, db, callback]);
}
});
} else {
if (err) {
self.log('Error when connecting to the database!');
//console.log(err);

if (typeof(callback) === 'function') {
callback.apply(self, [err]);
}
} else {
self.log('Connected to mongo DB ok, processing callbacks...');
self._connected.apply(self, [err, db, callback]);
}
}
});
};

/**
* Disconnect from the current mongo connection.
* @param callback
*/
disconnect: function (callback) {
this.log("Closing DB connection...");
this.client.close();

callback();
},

/**
* Called by the connect() method once a connection has been established
* or a connection error occurs.
* @param err
* @param db
* @param callback
* @private
*/
_connected: function (err, db, callback) {
if (!err) {
this.log('MongoDB connected successfully.');
this.emit('connected');
} else {
this.log('MongoDB connection error', 'error', err);
this.emit('connectionError');
}

if (typeof(callback) === 'function') {
callback.apply(this, [err, db]);
}
},
18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{
"author": "Rob Evans",
"name": "monge",
"description": "An easy to use library for accessing and working with MongoDB.",
"version": "1.0.0",
"repository": {
"git": "https://github.com/coolbloke1324/monge"
},
"main": "./index",
"dependencies": {
"mongodb": "1.1.1"
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "*"
}
}
7 changes: 7 additions & 0 deletions readme.md
@@ -0,0 +1,7 @@
# MongoEase
An easy to use library for accessing and working with MongoDB.

## Installation
```
npm install mongoease
```
1 change: 1 addition & 0 deletions tests/index.js
@@ -0,0 +1 @@
var monge = require('../index.js');

0 comments on commit c506878

Please sign in to comment.