Skip to content

Commit fbe269f

Browse files
authored
feat: v5 (#42)
2 parents 38b23d9 + fb08118 commit fbe269f

23 files changed

+668
-921
lines changed

.github/workflows/eslint.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ jobs:
2020
node-version: 16
2121

2222
- name: Install dependencies
23-
run: npm install
23+
run: yarn install
2424

2525
- name: Run ESLint
26-
run: npm run lint
27-
28-
- name: Run TSC
29-
run: npm run build:check
26+
run: yarn lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ test/
55
.vscode/
66
yarn.lock
77
package-lock.json
8+
globalConfig.json

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Snowflake Studio ❄️
3+
Copyright (c) 2022 CesiumLabs
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Quick Mongodb wrapper for beginners that provides key-value based interface.
77
# Installing
88

99
```bash
10-
$ npm install --save mongodb # required
1110
$ npm install --save quickmongo
1211
```
1312

@@ -16,7 +15,6 @@ $ npm install --save quickmongo
1615

1716
# Features
1817
- Beginner friendly
19-
- Strongly typed
2018
- Asynchronous
2119
- Dot notation support
2220
- Key-Value like interface
@@ -25,55 +23,47 @@ $ npm install --save quickmongo
2523
# Example
2624

2725
```js
28-
const { Collection: MongoCollection, MongoClient } = require("mongodb");
29-
const { Collection, Fields } = require("quickmongo");
30-
31-
const mongo = new MongoClient("mongodb://localhost/quickmongo");
32-
const schema = new Fields.ObjectField({
33-
difficulty: new Fields.StringField(),
34-
items: new Fields.ArrayField(new Fields.StringField()),
35-
balance: new Fields.NumberField()
26+
const { Database } = require("quickmongo");
27+
28+
const db = new Database("mongodb://localhost/quickmongo");
29+
30+
db.on("ready", () => {
31+
console.log("Connected to the database");
32+
doStuff();
3633
});
3734

38-
mongo.connect()
39-
.then(() => {
40-
console.log("Connected to the database!");
41-
doStuff();
42-
});
35+
db.connect();
4336

4437
function doStuff() {
45-
const mongoCollection = mongo.db().collection("JSON");
46-
47-
const db = new Collection(mongoCollection, schema);
48-
49-
db.set("userInfo", { difficulty: "Easy", items: [], balance: 0 }).then(console.log);
50-
// -> { difficulty: 'Easy', items: [], balance: 0 }
38+
// Setting an object in the database:
39+
await db.set("userInfo", { difficulty: "Easy" });
40+
// -> { difficulty: 'Easy' }
5141

52-
db.push("userInfo", "Sword", "items").then(console.log);
53-
// -> { difficulty: 'Easy', items: ['Sword'], balance: 0 }
42+
// Pushing an element to an array (that doesn't exist yet) in an object:
43+
await db.push("userInfo.items", "Sword");
44+
// -> { difficulty: 'Easy', items: ['Sword'] }
5445

55-
db.set("userInfo", 500, "balance").then(console.log);
46+
// Adding to a number (that doesn't exist yet) in an object:
47+
await db.add("userInfo.balance", 500);
5648
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
5749

5850
// Repeating previous examples:
59-
db.push("userInfo", "Watch", "items").then(console.log);
51+
await db.push("userInfo.items", "Watch");
6052
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
61-
62-
const previousBalance = await db.get("userInfo", "balance");
63-
db.set("userInfo", previousBalance + 500, "balance").then(console.log);
53+
await db.add("userInfo.balance", 500);
6454
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
6555

6656
// Fetching individual properties
67-
db.get("userInfo", "balance").then(console.log);
68-
// -> 1000
69-
db.get("userInfo", "items").then(console.log);
70-
// -> ['Sword', 'Watch']
57+
await db.get("userInfo.balance"); // -> 1000
58+
await db.get("userInfo.items"); // -> ['Sword', 'Watch']
7159

7260
// remove item
7361
db.pull("userInfo", "Sword", "items").then(console.log);
7462
// -> { difficulty: 'Easy', items: ['Watch'], balance: 1000 }
7563
}
7664
```
7765

66+
**Created and maintained by CesiumLabs**
67+
7868
# Discord Support
79-
**[SnowflakeDev Community ❄️](https://snowflakedev.org/discord)**
69+
**[CesiumLabs](https://discord.gg/uqB8kxh)**

__tests__/collection.spec.ts

Lines changed: 0 additions & 226 deletions
This file was deleted.

0 commit comments

Comments
 (0)