xpress-mongo
Advanced tools
Comparing version 0.0.11 to 0.0.12
11
index.js
@@ -14,3 +14,12 @@ const {MongoClient} = require('mongodb'); | ||
*/ | ||
function Client(url, options, errorCallback = undefined) { | ||
function Client(url, options = undefined, errorCallback = undefined) { | ||
/** | ||
* If first argument i.e url is an instance of MongoClient | ||
* We use it instead | ||
*/ | ||
if (url instanceof MongoClient) return new XMongoClient(url); | ||
/** | ||
* Else we create a new one | ||
*/ | ||
return new XMongoClient(new MongoClient(url, options)); | ||
@@ -17,0 +26,0 @@ } |
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Xpress-Mongo | ||
---- Still in development | ||
##### ---- Still in development | ||
Xpress-Mongo is a lightweight mongodb ODM both in size and in actions. | ||
Unlike other Mongodb ODM's, xpress keeps you closer to **mongodb-native** calls using the `raw` function available on all model instances | ||
```javascript | ||
// Using | ||
const User = SomeCollection(); | ||
User.findOne(); // XpressMongo findOne | ||
User.raw.findOne(); // Mongodb findOne | ||
``` | ||
### Setup | ||
Assuming you already have your client connected already.. | ||
```javascript | ||
// Import XpressMongo | ||
const {Client} = require('xpress-mongo'); | ||
// Use your already existing client. | ||
const Database = Client('your_client').useDb('database_name'); | ||
// Define models using collection names | ||
const UserModel = Database.model('users'); | ||
const PostModel = Database.model('posts'); | ||
UserModel.findOne().then(user => console.log(user)); | ||
PostModel.find().then(posts => console.log(posts)); | ||
``` | ||
### Model | ||
@@ -5,0 +37,0 @@ ```javascript |
@@ -1,15 +0,14 @@ | ||
const {Users, Contacts} = require('./models'); | ||
const helpers = require('../fns/projection'); | ||
const Chance = require('chance'); | ||
const chance = new Chance(); | ||
const {Client} = require('../index'); | ||
const mongodb = require('mongodb'); | ||
mongodb.MongoClient.connect( | ||
'mongodb://localhost/test_model', | ||
{useNewUrlParser: true, useUnifiedTopology: true} | ||
).then(async client => { | ||
const Database = Client(client).useDb('test_model'); | ||
const UserModel = Database.model('users'); | ||
async function run() { | ||
const data = await Users.toArray(r => r.find()); | ||
console.log(data); | ||
} | ||
run().then(() => { | ||
// process.exit(); | ||
}); | ||
console.log(await UserModel.findOne()) | ||
}).catch(err => { | ||
console.log(err); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31124
959
69