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 +67 -9
- package/dist/sorla.min.js +1 -1
- package/index.d.ts +89 -0
- package/index.mjs +5 -0
- package/package.json +27 -3
- package/src/documents/cursor.js +80 -16
- package/src/documents/document.js +26 -30
- package/src/query_language/manipulation.js +84 -47
- package/src/utils.js +9 -8
- package/Brainstorming.md +0 -22
- package/debug-not.js +0 -24
- package/example/simple_data_example.html +0 -196
- package/index.js +0 -62
- package/src/helper.js +0 -41
- package/test/feature_collection.test.js +0 -75
- package/test/feature_collection_queries.test.js +0 -224
- package/test/feature_cursor.test.js +0 -84
- package/test/feature_database.test.js +0 -62
- package/test/feature_insert.test.js +0 -116
- package/test/feature_nested_queries.test.js +0 -94
- package/test/feature_query_equivalence.test.js +0 -165
- package/test/unit_database.test.js +0 -36
- package/test/unit_document.test.js +0 -39
- package/test/unit_operators.test.js +0 -78
- package/test/unit_sorla.test.js +0 -42
- package/test/unit_test.test.js +0 -25
- package/webpack.config.js +0 -11
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
|
-
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
7
8
|
```
|
|
8
|
-
|
|
9
|
+
npm install sorla-db
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
```js
|
|
13
|
+
// Node / bundlers
|
|
14
|
+
const sorla = require('sorla-db');
|
|
15
|
+
// or
|
|
16
|
+
import sorla from 'sorla-db';
|
|
14
17
|
```
|
|
15
|
-
|
|
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
|
|
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
|