twin-db 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
### Before All
|
|
2
|
+
Make sure you're using `"type": "module"` in package.json.<br>
|
|
3
|
+
Make sure to pass just values that JSON accepts, if not, the values will be changed to `null`.
|
|
4
|
+
# How to Use?
|
|
5
|
+
To create a new database make the following step:
|
|
6
|
+
```js
|
|
7
|
+
import TwinDB from 'twin-db';
|
|
8
|
+
const database = new TwinDB('db');
|
|
9
|
+
```
|
|
10
|
+
And your database is done.
|
|
11
|
+
### You can make various databases too:
|
|
12
|
+
```js
|
|
13
|
+
import TwinDB from 'twin-db';
|
|
14
|
+
const database = new TwinDB('db');
|
|
15
|
+
const coolDatabase = new TwinDB('cool');
|
|
16
|
+
```
|
|
17
|
+
# Database Methods
|
|
18
|
+
Now we going to explain you the database methods.<br>
|
|
19
|
+
Imagine the following data from a random database:
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"name": "Daniel",
|
|
23
|
+
"surname": "Costa",
|
|
24
|
+
"age": 60,
|
|
25
|
+
"cool": false,
|
|
26
|
+
"hobbies": ["cs", "pizza"],
|
|
27
|
+
"address": {
|
|
28
|
+
"city": "I dont",
|
|
29
|
+
"state": "ES",
|
|
30
|
+
"country": "Brazil"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
### 1. Set Method
|
|
35
|
+
This one changes the value of a path to the value you passed.
|
|
36
|
+
```js
|
|
37
|
+
database.set('name', 'De'); // now the name is "De".
|
|
38
|
+
database.set('age', 50); // now the age is 50.
|
|
39
|
+
```
|
|
40
|
+
- To go through the object, make sure to use ".", like `address.city`.
|
|
41
|
+
### 2. Get Method
|
|
42
|
+
Get a value from a given path.
|
|
43
|
+
```js
|
|
44
|
+
database.get('surname'); // returns "Costa".
|
|
45
|
+
```
|
|
46
|
+
### 3. Delete Method
|
|
47
|
+
Deletes a value from data.
|
|
48
|
+
```js
|
|
49
|
+
database.delete('cool') // now the cool value no longer exists.
|
|
50
|
+
database.delete('address.country') // now the country no longer exists too.
|
|
51
|
+
```
|
|
52
|
+
### 4. Sum Method
|
|
53
|
+
Sum the current value of the given path with the given value.
|
|
54
|
+
```js
|
|
55
|
+
database.sum('age', 30); // now the age is 80.
|
|
56
|
+
```
|
|
57
|
+
### 5. Sub Method
|
|
58
|
+
Subtract the current value of the given path with the given value.
|
|
59
|
+
```js
|
|
60
|
+
database.sub('age', 10); // now the age is 70.
|
|
61
|
+
```
|
|
62
|
+
### 6. Concat Method
|
|
63
|
+
Concatenate the current value of the given path with the given value.
|
|
64
|
+
```js
|
|
65
|
+
database.concat('address.city', ' know'); // now the city is "I dont know".
|
|
66
|
+
```
|
|
67
|
+
### 7. Push Method
|
|
68
|
+
Push the given values into the current value array.
|
|
69
|
+
```js
|
|
70
|
+
database.push('hobbies', 'sleep', 'valorant'); // now the hobbies is ["cs", "pizza", "sleep", "valorant"].
|
|
71
|
+
```
|
|
72
|
+
### 8. Pull Method
|
|
73
|
+
```js
|
|
74
|
+
database.pull('hobbies', 'cs', 'sleep') // now the hobbies is ["pizza", "valorant"].
|
|
75
|
+
```
|
|
76
|
+
### Now the data object will looks like that:
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"name": "De",
|
|
80
|
+
"surname": "Costa",
|
|
81
|
+
"age": 70,
|
|
82
|
+
"hobbies": ["pizza", "valorant"],
|
|
83
|
+
"address": {
|
|
84
|
+
"city": "I dont know",
|
|
85
|
+
"state": "ES"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|