sorla-db 1.1.0 → 1.2.0

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 CHANGED
@@ -3,24 +3,34 @@ A simple and temporary database focused to use in browser environment that will
3
3
 
4
4
  This idea is from our founder #andmarruda that give this idea and alot of this idea are developed by him.
5
5
 
6
- To create a minify file run
6
+ ## Installation
7
+
7
8
  ```
8
- node index.js
9
+ npm install sorla-db
9
10
  ```
10
11
 
11
- To test the environment using jest run...
12
- Don`t forget to install the dev dependecies before, using:
13
-
12
+ ```js
13
+ // Node / bundlers
14
+ const sorla = require('sorla-db');
15
+ // or
16
+ import sorla from 'sorla-db';
14
17
  ```
15
- npm install --only=dev
18
+
19
+ ```html
20
+ <!-- browser, 9.5 kB: registers window.sorla -->
21
+ <script src="https://cdn.jsdelivr.net/npm/sorla-db@1/dist/sorla.min.js"></script>
16
22
  ```
17
23
 
24
+ TypeScript declarations are included.
25
+
26
+ ## Development
27
+
18
28
  ```
19
- npm test
29
+ npm install
30
+ npm test # jest
31
+ npm run build # dist/sorla.min.js
20
32
  ```
21
33
 
22
- Soon some documentations....
23
-
24
34
  Prohibited characters $ and .,
25
35
  $ because is used to call operators and . because uses to search key inside a object's object
26
36
 
@@ -42,6 +52,54 @@ window.sorla.db.updatedTags.insertMany([
42
52
  ]);
43
53
  ```
44
54
 
55
+ ## Inserting documents
56
+
57
+ `insertOne` stores a **copy** of the document and returns its `_id` (a uuid v4 when the document
58
+ has none). `insertMany` validates the whole array first, so an invalid document never leaves the
59
+ collection with half of the batch, and returns the ids.
60
+
61
+ ```
62
+ const id = window.sorla.db.updatedTags.insertOne({ name: 'Ana', nickname: null });
63
+ const ids = window.sorla.db.updatedTags.insertMany([{ name: 'Bia' }, { _id: 'custom', name: 'Caio' }]);
64
+ ```
65
+
66
+ - `null` values are allowed, at any depth
67
+ - a duplicated `_id` throws
68
+ - keys with `$` or `.` throw, at any depth
69
+ - values must be cloneable (no functions or DOM nodes)
70
+
71
+ Documents returned by the collection are read-only: assigning a field throws.
72
+
73
+ ## Reading results
74
+
75
+ `find()` returns a cursor:
76
+
77
+ ```
78
+ const cursor = window.sorla.db.updatedTags.find({ age: { $gte: 18 } });
79
+ cursor.length; // number of documents
80
+ cursor.first(); // data of the first one, null when empty
81
+ cursor.last(); // data of the last one, null when empty
82
+ cursor.toArray(); // plain copies
83
+ while(cursor.hasNext()) cursor.next();
84
+ ```
85
+
86
+ `findOne()` returns the data of the first matching document, or `null`.
87
+
88
+ ## Sorting
89
+
90
+ ```
91
+ window.sorla.db.updatedTags.find({}).sort({ age: -1, name: 1 }).toArray();
92
+ ```
93
+
94
+ `1` is ascending and `-1` descending, and `"a.b"` paths work. `sort()` returns the cursor. Values of
95
+ different types follow MongoDB's order: missing and null, numbers, strings, objects, arrays,
96
+ booleans, dates. Strings compare by code point. Pass a collation to compare by language rules,
97
+ using the `Intl.Collator` options:
98
+
99
+ ```
100
+ cursor.sort({ name: 1 }, { collation: { locale: 'pt-BR', sensitivity: 'base', numeric: true } });
101
+ ```
102
+
45
103
  ## Find Operators
46
104
 
47
105
  ### $and