sorla-db 1.0.0 → 1.1.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.
@@ -1,196 +1,196 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Simple Data Example</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- </head>
8
- <body>
9
- <p><b>Total Items:</b> <span id="total-items"></span></p><hr>
10
-
11
- <h3>Add you data:</h3>
12
- <div>
13
- <label>Name</label>
14
- <input type="text" id="name" placeholder="Name">
15
- </div>
16
- <div>
17
- <label>Inscription</label>
18
- <input type="number" step="1" min="1" id="inscription" placeholder="Inscription">
19
- </div>
20
- <div>
21
- <label>Age</label>
22
- <input type="number" step="1" min="1" id="age" placeholder="Age">
23
- </div>
24
- <div>
25
- <label>Father</label>
26
- <input type="text" id="father" placeholder="Father">
27
- </div>
28
- <div>
29
- <label>Mother</label>
30
- <input type="text" id="mother" placeholder="Mother">
31
- </div>
32
- <button type="button" id="add-data">Add data</button>
33
- <hr>
34
-
35
- <h3>Seach data</h3>
36
- <div>
37
- <label>Search by</label>
38
- <input type="text" id="search-name" placeholder="Search by">
39
- <select id="search-name-type">
40
- <option value="name">Name</option>
41
- <option value="inscription">Inscription</option>
42
- <option value="age">Age</option>
43
- <option value="parents.father">Father</option>
44
- <option value="parents.mother">Mother</option>
45
- </select>
46
- <button type="button" id="search-by-btn">Search</button>
47
- </div>
48
-
49
- <div>
50
- <textarea id="search-result" cols="30" rows="10"></textarea>
51
- </div>
52
-
53
- <script src="../dist/sorla.min.js"></script>
54
-
55
- <script>
56
- function generateUUID() {
57
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
58
- var r = Math.random() * 16 | 0,
59
- v = c == 'x' ? r : (r & 0x3 | 0x8);
60
- return v.toString(16);
61
- });
62
- }
63
-
64
- addItem = () => {
65
- const name = document.getElementById('name').value;
66
- const inscription = document.getElementById('inscription').value;
67
- const age = document.getElementById('age').value;
68
- const father = document.getElementById('father').value;
69
- const mother = document.getElementById('mother').value;
70
-
71
- s.db.simple.insertOne({
72
- 'name': name,
73
- 'inscription': inscription,
74
- 'age': age,
75
- 'parents': {
76
- 'father': father,
77
- 'mother': mother
78
- }
79
- });
80
-
81
- document.getElementById('total-items').innerText = s.db.simple.count();
82
- }
83
-
84
- searchData = () => {
85
- const searchName = document.getElementById('search-name').value;
86
- const searchNameType = document.getElementById('search-name-type').value;
87
-
88
- const result = s.db.simple.findOne({
89
- [searchNameType]: searchName
90
- });
91
-
92
- console.log(result);
93
-
94
- document.getElementById('search-result').value = JSON.stringify(result, null, 4);
95
- }
96
-
97
- document.addEventListener('DOMContentLoaded', () => {
98
- window.s = new sorla();
99
- s.useDb('simple_database');
100
- s.db.createCollection('simple');
101
- const uuid_fix = generateUUID();
102
-
103
- //creating data
104
- s.db.simple.insertMany([
105
- {
106
- 'name': 'John Doe',
107
- 'inscription': 123,
108
- 'age': 25,
109
- 'parents': {
110
- 'father': 'John Doe Sr.',
111
- 'mother': 'Jane Doe'
112
- },
113
- 'uuid': generateUUID()
114
- },
115
-
116
- {
117
- "name": "Elizabeth Davis",
118
- "inscription": 618,
119
- "age": 36,
120
- "parents": {
121
- "father": "Elizabeth Brown",
122
- "mother": "Elizabeth Brown"
123
- },
124
- 'uuid': generateUUID()
125
- },
126
-
127
-
128
- {
129
- "name": "John Davis",
130
- "inscription": 817,
131
- "age": 54,
132
- "parents": {
133
- "father": "John Garcia",
134
- "mother": "Patricia Garcia"
135
- },
136
- 'uuid': uuid_fix
137
- },
138
-
139
- {
140
- "name": "Jennifer Miller",
141
- "inscription": 699,
142
- "age": 45,
143
- "parents": {
144
- "father": "Linda Brown",
145
- "mother": "Elizabeth Brown"
146
- },
147
- 'uuid': generateUUID()
148
- },
149
-
150
- {
151
- "name": "Patricia Johnson",
152
- "inscription": 906,
153
- "age": 49,
154
- "parents": {
155
- "father": "Robert Johnson",
156
- "mother": "Elizabeth Johnson"
157
- },
158
- 'uuid': generateUUID()
159
- },
160
-
161
- {
162
- "name": "Michael Johnson",
163
- "inscription": 810,
164
- "age": 20,
165
- "parents": {
166
- "father": "Jennifer Brown",
167
- "mother": "Jennifer Brown"
168
- },
169
- 'uuid': generateUUID()
170
- }
171
- ]);
172
-
173
- document.getElementById('total-items').innerText = s.db.simple.count();
174
- document.getElementById('add-data').addEventListener('click', addItem);
175
- document.getElementById('search-by-btn').addEventListener('click', searchData);
176
-
177
- //operators test
178
- //testing search and
179
- /*const result = s.db.simple.find({'$and': [{'name': 'John Doe'}, {'age': 25}]}, {_id: 0}); //should return 1
180
- console.log('and', result);
181
-
182
- //testing search or
183
- const result2 = s.db.simple.find({'$or': [{'name': 'John Doe'}, {'parents.mother': 'Elizabeth Johnson'}]}); //should return 2
184
- console.log('or', result2);
185
-
186
- //testing search uuid
187
- const result3 = s.db.simple.findOne({'uuid': uuid_fix});
188
- console.log('uuid', uuid_fix, result3);*/
189
-
190
- //search uuid with not
191
- const result4 = s.db.simple.find({'uuid': {'$not': uuid_fix}});
192
- console.log('uuid not', uuid_fix, result4);
193
- });
194
- </script>
195
- </body>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Simple Data Example</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ </head>
8
+ <body>
9
+ <p><b>Total Items:</b> <span id="total-items"></span></p><hr>
10
+
11
+ <h3>Add you data:</h3>
12
+ <div>
13
+ <label>Name</label>
14
+ <input type="text" id="name" placeholder="Name">
15
+ </div>
16
+ <div>
17
+ <label>Inscription</label>
18
+ <input type="number" step="1" min="1" id="inscription" placeholder="Inscription">
19
+ </div>
20
+ <div>
21
+ <label>Age</label>
22
+ <input type="number" step="1" min="1" id="age" placeholder="Age">
23
+ </div>
24
+ <div>
25
+ <label>Father</label>
26
+ <input type="text" id="father" placeholder="Father">
27
+ </div>
28
+ <div>
29
+ <label>Mother</label>
30
+ <input type="text" id="mother" placeholder="Mother">
31
+ </div>
32
+ <button type="button" id="add-data">Add data</button>
33
+ <hr>
34
+
35
+ <h3>Seach data</h3>
36
+ <div>
37
+ <label>Search by</label>
38
+ <input type="text" id="search-name" placeholder="Search by">
39
+ <select id="search-name-type">
40
+ <option value="name">Name</option>
41
+ <option value="inscription">Inscription</option>
42
+ <option value="age">Age</option>
43
+ <option value="parents.father">Father</option>
44
+ <option value="parents.mother">Mother</option>
45
+ </select>
46
+ <button type="button" id="search-by-btn">Search</button>
47
+ </div>
48
+
49
+ <div>
50
+ <textarea id="search-result" cols="30" rows="10"></textarea>
51
+ </div>
52
+
53
+ <script src="../dist/sorla.min.js"></script>
54
+
55
+ <script>
56
+ function generateUUID() {
57
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
58
+ var r = Math.random() * 16 | 0,
59
+ v = c == 'x' ? r : (r & 0x3 | 0x8);
60
+ return v.toString(16);
61
+ });
62
+ }
63
+
64
+ addItem = () => {
65
+ const name = document.getElementById('name').value;
66
+ const inscription = document.getElementById('inscription').value;
67
+ const age = document.getElementById('age').value;
68
+ const father = document.getElementById('father').value;
69
+ const mother = document.getElementById('mother').value;
70
+
71
+ s.db.simple.insertOne({
72
+ 'name': name,
73
+ 'inscription': inscription,
74
+ 'age': age,
75
+ 'parents': {
76
+ 'father': father,
77
+ 'mother': mother
78
+ }
79
+ });
80
+
81
+ document.getElementById('total-items').innerText = s.db.simple.count();
82
+ }
83
+
84
+ searchData = () => {
85
+ const searchName = document.getElementById('search-name').value;
86
+ const searchNameType = document.getElementById('search-name-type').value;
87
+
88
+ const result = s.db.simple.findOne({
89
+ [searchNameType]: searchName
90
+ });
91
+
92
+ console.log(result);
93
+
94
+ document.getElementById('search-result').value = JSON.stringify(result, null, 4);
95
+ }
96
+
97
+ document.addEventListener('DOMContentLoaded', () => {
98
+ window.s = new sorla();
99
+ s.useDb('simple_database');
100
+ s.db.createCollection('simple');
101
+ const uuid_fix = generateUUID();
102
+
103
+ //creating data
104
+ s.db.simple.insertMany([
105
+ {
106
+ 'name': 'John Doe',
107
+ 'inscription': 123,
108
+ 'age': 25,
109
+ 'parents': {
110
+ 'father': 'John Doe Sr.',
111
+ 'mother': 'Jane Doe'
112
+ },
113
+ 'uuid': generateUUID()
114
+ },
115
+
116
+ {
117
+ "name": "Elizabeth Davis",
118
+ "inscription": 618,
119
+ "age": 36,
120
+ "parents": {
121
+ "father": "Elizabeth Brown",
122
+ "mother": "Elizabeth Brown"
123
+ },
124
+ 'uuid': generateUUID()
125
+ },
126
+
127
+
128
+ {
129
+ "name": "John Davis",
130
+ "inscription": 817,
131
+ "age": 54,
132
+ "parents": {
133
+ "father": "John Garcia",
134
+ "mother": "Patricia Garcia"
135
+ },
136
+ 'uuid': uuid_fix
137
+ },
138
+
139
+ {
140
+ "name": "Jennifer Miller",
141
+ "inscription": 699,
142
+ "age": 45,
143
+ "parents": {
144
+ "father": "Linda Brown",
145
+ "mother": "Elizabeth Brown"
146
+ },
147
+ 'uuid': generateUUID()
148
+ },
149
+
150
+ {
151
+ "name": "Patricia Johnson",
152
+ "inscription": 906,
153
+ "age": 49,
154
+ "parents": {
155
+ "father": "Robert Johnson",
156
+ "mother": "Elizabeth Johnson"
157
+ },
158
+ 'uuid': generateUUID()
159
+ },
160
+
161
+ {
162
+ "name": "Michael Johnson",
163
+ "inscription": 810,
164
+ "age": 20,
165
+ "parents": {
166
+ "father": "Jennifer Brown",
167
+ "mother": "Jennifer Brown"
168
+ },
169
+ 'uuid': generateUUID()
170
+ }
171
+ ]);
172
+
173
+ document.getElementById('total-items').innerText = s.db.simple.count();
174
+ document.getElementById('add-data').addEventListener('click', addItem);
175
+ document.getElementById('search-by-btn').addEventListener('click', searchData);
176
+
177
+ //operators test
178
+ //testing search and
179
+ /*const result = s.db.simple.find({'$and': [{'name': 'John Doe'}, {'age': 25}]}, {_id: 0}); //should return 1
180
+ console.log('and', result);
181
+
182
+ //testing search or
183
+ const result2 = s.db.simple.find({'$or': [{'name': 'John Doe'}, {'parents.mother': 'Elizabeth Johnson'}]}); //should return 2
184
+ console.log('or', result2);
185
+
186
+ //testing search uuid
187
+ const result3 = s.db.simple.findOne({'uuid': uuid_fix});
188
+ console.log('uuid', uuid_fix, result3);*/
189
+
190
+ //search uuid with not
191
+ const result4 = s.db.simple.find({'uuid': {'$not': uuid_fix}});
192
+ console.log('uuid not', uuid_fix, result4);
193
+ });
194
+ </script>
195
+ </body>
196
196
  </html>
package/index.js CHANGED
@@ -1,62 +1,62 @@
1
-
2
- const fs = require('fs-extra');
3
- const browserify = require('browserify');
4
- const path = require('path');
5
- const terser = require('terser');
6
-
7
- const srcDir = './src';
8
- const distDir = './dist';
9
- const outputFile = `${distDir}/sorla.min.js`;
10
-
11
- function findJsFiles(dir, fileList = [])
12
- {
13
- const files = fs.readdirSync(dir);
14
- files.forEach(file => {
15
- const filePath = path.join(dir, file);
16
- const stat = fs.statSync(filePath);
17
- if (stat.isDirectory())
18
- {
19
- findJsFiles(filePath, fileList);
20
- }
21
- else if (path.extname(filePath) === '.js')
22
- {
23
- fileList.push(filePath);
24
- }
25
- });
26
- return fileList;
27
- }
28
-
29
- function buildForBrowser(entryFile, outputFile) {
30
- const b = browserify();
31
- b.add(entryFile);
32
- b.bundle(async (err, buf) => {
33
- if (err) {
34
- console.error(err);
35
- return;
36
- }
37
-
38
- const code = buf.toString();
39
- try {
40
- const minified = await terser.minify(code, {
41
- compress: true,
42
- mangle: {
43
- keep_classnames: true,
44
- keep_fnames: true
45
- }
46
- });
47
-
48
- if (minified.error) {
49
- console.error(minified.error);
50
- return;
51
- }
52
-
53
- fs.outputFileSync(outputFile, code);
54
- fs.outputFileSync(outputFile, minified.code);
55
- } catch (minifyErr) {
56
- console.error(minifyErr);
57
- }
58
- });
59
- }
60
-
61
- const allJsFiles = findJsFiles(srcDir);
1
+
2
+ const fs = require('fs-extra');
3
+ const browserify = require('browserify');
4
+ const path = require('path');
5
+ const terser = require('terser');
6
+
7
+ const srcDir = './src';
8
+ const distDir = './dist';
9
+ const outputFile = `${distDir}/sorla.min.js`;
10
+
11
+ function findJsFiles(dir, fileList = [])
12
+ {
13
+ const files = fs.readdirSync(dir);
14
+ files.forEach(file => {
15
+ const filePath = path.join(dir, file);
16
+ const stat = fs.statSync(filePath);
17
+ if (stat.isDirectory())
18
+ {
19
+ findJsFiles(filePath, fileList);
20
+ }
21
+ else if (path.extname(filePath) === '.js')
22
+ {
23
+ fileList.push(filePath);
24
+ }
25
+ });
26
+ return fileList;
27
+ }
28
+
29
+ function buildForBrowser(entryFile, outputFile) {
30
+ const b = browserify();
31
+ b.add(entryFile);
32
+ b.bundle(async (err, buf) => {
33
+ if (err) {
34
+ console.error(err);
35
+ return;
36
+ }
37
+
38
+ const code = buf.toString();
39
+ try {
40
+ const minified = await terser.minify(code, {
41
+ compress: true,
42
+ mangle: {
43
+ keep_classnames: true,
44
+ keep_fnames: true
45
+ }
46
+ });
47
+
48
+ if (minified.error) {
49
+ console.error(minified.error);
50
+ return;
51
+ }
52
+
53
+ fs.outputFileSync(outputFile, code);
54
+ fs.outputFileSync(outputFile, minified.code);
55
+ } catch (minifyErr) {
56
+ console.error(minifyErr);
57
+ }
58
+ });
59
+ }
60
+
61
+ const allJsFiles = findJsFiles(srcDir);
62
62
  buildForBrowser(allJsFiles, outputFile);
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "sorla-db",
3
- "version": "1.0.0",
4
- "description": "A simple and temporary database focused to use in browser environment that will bring capabilities for other tools that will be launched as soon as possible.",
5
- "main": "dist/sorla.min.js",
6
- "scripts": {
7
- "mini": "node index.js",
8
- "build": "webpack",
9
- "test": "jest"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/sysborg/sorla-db.git"
14
- },
15
- "keywords": [
16
- "nosql",
17
- "browser",
18
- "database",
19
- "sorla",
20
- "sysborg",
21
- "anderson",
22
- "arruda",
23
- "andmarruda"
24
- ],
25
- "author": "Anderson Arruda < andmarruda@gmail.com >",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/sysborg/sorla-db/issues"
29
- },
30
- "homepage": "https://github.com/sysborg/sorla-db#readme",
31
- "devDependencies": {
32
- "browserify": "^17.0.0",
33
- "chai": "^4.3.8",
34
- "faker": "^5.5.3",
35
- "fs-extra": "^11.2.0",
36
- "jest": "^29.6.4",
37
- "jsdom": "^22.1.0",
38
- "jsdom-global": "^3.0.2",
39
- "mocha": "^10.2.0",
40
- "terser": "^5.27.0"
41
- }
42
- }
1
+ {
2
+ "name": "sorla-db",
3
+ "version": "1.1.0",
4
+ "description": "A simple and temporary database focused to use in browser environment that will bring capabilities for other tools that will be launched as soon as possible.",
5
+ "main": "dist/sorla.min.js",
6
+ "scripts": {
7
+ "mini": "node index.js",
8
+ "build": "webpack",
9
+ "test": "jest"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/sysborg/sorla-db.git"
14
+ },
15
+ "keywords": [
16
+ "nosql",
17
+ "browser",
18
+ "database",
19
+ "sorla",
20
+ "sysborg",
21
+ "anderson",
22
+ "arruda",
23
+ "andmarruda"
24
+ ],
25
+ "author": "Anderson Arruda < andmarruda@gmail.com >",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/sysborg/sorla-db/issues"
29
+ },
30
+ "homepage": "https://github.com/sysborg/sorla-db#readme",
31
+ "devDependencies": {
32
+ "browserify": "^17.0.0",
33
+ "chai": "^4.3.8",
34
+ "faker": "^5.5.3",
35
+ "fs-extra": "^11.2.0",
36
+ "jest": "^29.6.4",
37
+ "jsdom": "^22.1.0",
38
+ "jsdom-global": "^3.0.2",
39
+ "mocha": "^10.2.0",
40
+ "terser": "^5.27.0"
41
+ }
42
+ }