Skip to content

Commit eefb324

Browse files
Bump version to 0.2.0
1 parent c250379 commit eefb324

File tree

6 files changed

+57
-38
lines changed

6 files changed

+57
-38
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# @useful/mongo
2+
3+
## Example usage
4+
5+
```js
6+
import {
7+
connect,
8+
disconnect,
9+
getDatabase,
10+
getCollection,
11+
generateId
12+
} from "@userful/mongo";
13+
14+
(async function() {
15+
await connect();
16+
const Users = await getCollection("users");
17+
const user = await Users.findOne({});
18+
await Users.insert({
19+
_id: generateId()
20+
/* Other fields */
21+
});
22+
await disconnect();
23+
})();
24+
```

dist/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const disconnect = async () => {
5050
}
5151
};
5252
/**
53-
* Disconnects from database.
53+
* Gets database.
5454
*
5555
* @function getDatabase
5656
* @return {Db} MongoDB instance of the Db class.
@@ -59,9 +59,9 @@ const disconnect = async () => {
5959

6060
exports.disconnect = disconnect;
6161

62-
const getDatabase = () => {
62+
const getDatabase = async () => {
6363
if (!client) {
64-
throw new Error("Not connected to database");
64+
await connect();
6565
}
6666

6767
return db;
@@ -76,9 +76,9 @@ const getDatabase = () => {
7676

7777
exports.getDatabase = getDatabase;
7878

79-
const getCollection = collectionName => {
79+
const getCollection = async collectionName => {
8080
if (!client) {
81-
throw new Error("Not connected to database");
81+
await connect();
8282
} // Get collection.
8383

8484

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 19 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
{
22
"name": "@useful/mongo",
3-
"version": "0.1.5",
3+
"version": "0.2.0",
44
"description": "Package created with NPG (Node Package Generator)",
55
"main": "dist/index.js",
6-
"scripts": {
7-
"build": "npg build -v 8.10",
8-
"start": "npg start"
9-
},
10-
"devDependencies": {
11-
"npg": "^0.2.0"
12-
},
136
"dependencies": {
14-
"@babel/runtime": "^7.0.0-beta.44",
15-
"mongodb": "^3.0.5"
7+
"@babel/runtime": "^7.0.0-beta.46",
8+
"mongodb": "^3.0.8"
169
}
1710
}

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ const disconnect = async () => {
3838
};
3939

4040
/**
41-
* Disconnects from database.
41+
* Gets database.
4242
*
4343
* @function getDatabase
4444
* @return {Db} MongoDB instance of the Db class.
4545
*/
46-
const getDatabase = () => {
46+
const getDatabase = async () => {
4747
if (!client) {
48-
throw new Error("Not connected to database");
48+
await connect();
4949
}
5050
return db;
5151
};
@@ -56,9 +56,9 @@ const getDatabase = () => {
5656
* @function getCollection
5757
* @return {Collection<TSchema>} MongoDB instance of the Collection class.
5858
*/
59-
const getCollection = collectionName => {
59+
const getCollection = async collectionName => {
6060
if (!client) {
61-
throw new Error("Not connected to database");
61+
await connect();
6262
}
6363
// Get collection.
6464
return db.collection(collectionName);

0 commit comments

Comments
 (0)