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.
- package/Brainstorming.md +21 -21
- package/LICENSE +21 -21
- package/README.md +216 -31
- package/debug-not.js +23 -23
- package/dist/sorla.min.js +1 -1
- package/example/simple_data_example.html +195 -195
- package/index.js +61 -61
- package/package.json +42 -42
- package/src/collections/collection.js +46 -46
- package/src/dbs/database.js +71 -71
- package/src/documents/cursor.js +143 -143
- package/src/documents/document.js +87 -87
- package/src/helper.js +40 -40
- package/src/query_language/manipulation.js +160 -160
- package/src/query_language/operators.js +242 -288
- package/src/query_language/query.js +73 -103
- package/src/sorla.js +122 -122
- package/src/utils.js +40 -40
- package/test/feature_collection.test.js +74 -72
- package/test/feature_collection_queries.test.js +223 -268
- package/test/feature_cursor.test.js +84 -0
- package/test/feature_database.test.js +62 -0
- package/test/feature_insert.test.js +116 -0
- package/test/feature_nested_queries.test.js +94 -0
- package/test/feature_query_equivalence.test.js +165 -0
- package/test/unit_database.test.js +35 -35
- package/test/{unit_document_test.js → unit_document.test.js} +38 -38
- package/test/unit_operators.test.js +78 -0
- package/test/unit_sorla.test.js +41 -41
- package/test/unit_test.test.js +24 -24
- package/webpack.config.js +10 -10
|
@@ -1,104 +1,74 @@
|
|
|
1
|
-
const manipulation = require('./manipulation.js');
|
|
2
|
-
const operators = require('./operators.js');
|
|
3
|
-
const cursor = require('../documents/cursor.js');
|
|
4
|
-
|
|
5
|
-
class query extends manipulation
|
|
6
|
-
{
|
|
7
|
-
constructor(validationSchema)
|
|
8
|
-
{
|
|
9
|
-
super(validationSchema);
|
|
10
|
-
this._operators = new operators();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Count documents
|
|
15
|
-
* @return int
|
|
16
|
-
*/
|
|
17
|
-
count()
|
|
18
|
-
{
|
|
19
|
-
return this._documents.length;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Deeps find in object
|
|
24
|
-
* @param object query
|
|
25
|
-
* @param object projection
|
|
26
|
-
* @param bool firstOne
|
|
27
|
-
* @return array
|
|
28
|
-
*/
|
|
29
|
-
_deepFind(query, projection, single=false)
|
|
30
|
-
{
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Find one document
|
|
76
|
-
* @param query
|
|
77
|
-
* @param projection
|
|
78
|
-
* @return object
|
|
79
|
-
*/
|
|
80
|
-
findOne(query, projection = null)
|
|
81
|
-
{
|
|
82
|
-
const finded = this._deepFind(query, projection, true);
|
|
83
|
-
return finded.first();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Find documents
|
|
88
|
-
* @param query
|
|
89
|
-
* @param projection
|
|
90
|
-
* @return array
|
|
91
|
-
*/
|
|
92
|
-
find(query, projection = null)
|
|
93
|
-
{
|
|
94
|
-
const finded = this._deepFind(query, projection);
|
|
95
|
-
return finded;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//find
|
|
99
|
-
//find one and delete
|
|
100
|
-
//find one and update
|
|
101
|
-
//find one and replace
|
|
102
|
-
}
|
|
103
|
-
|
|
1
|
+
const manipulation = require('./manipulation.js');
|
|
2
|
+
const operators = require('./operators.js');
|
|
3
|
+
const cursor = require('../documents/cursor.js');
|
|
4
|
+
|
|
5
|
+
class query extends manipulation
|
|
6
|
+
{
|
|
7
|
+
constructor(validationSchema)
|
|
8
|
+
{
|
|
9
|
+
super(validationSchema);
|
|
10
|
+
this._operators = new operators();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Count documents
|
|
15
|
+
* @return int
|
|
16
|
+
*/
|
|
17
|
+
count()
|
|
18
|
+
{
|
|
19
|
+
return this._documents.length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Deeps find in object
|
|
24
|
+
* @param object query
|
|
25
|
+
* @param object projection
|
|
26
|
+
* @param bool firstOne
|
|
27
|
+
* @return array
|
|
28
|
+
*/
|
|
29
|
+
_deepFind(query, projection, single=false)
|
|
30
|
+
{
|
|
31
|
+
const finded = [];
|
|
32
|
+
for(const doc of this._documents)
|
|
33
|
+
{
|
|
34
|
+
if(!this._operators.matches(doc, query))
|
|
35
|
+
continue;
|
|
36
|
+
|
|
37
|
+
finded.push(doc.clone());
|
|
38
|
+
if(single) break;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new cursor(finded, projection);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Find one document
|
|
46
|
+
* @param query
|
|
47
|
+
* @param projection
|
|
48
|
+
* @return object
|
|
49
|
+
*/
|
|
50
|
+
findOne(query, projection = null)
|
|
51
|
+
{
|
|
52
|
+
const finded = this._deepFind(query, projection, true);
|
|
53
|
+
return finded.first();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Find documents
|
|
58
|
+
* @param query
|
|
59
|
+
* @param projection
|
|
60
|
+
* @return array
|
|
61
|
+
*/
|
|
62
|
+
find(query, projection = null)
|
|
63
|
+
{
|
|
64
|
+
const finded = this._deepFind(query, projection);
|
|
65
|
+
return finded;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//find
|
|
69
|
+
//find one and delete
|
|
70
|
+
//find one and update
|
|
71
|
+
//find one and replace
|
|
72
|
+
}
|
|
73
|
+
|
|
104
74
|
module.exports = query;
|
package/src/sorla.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
const database = require('./dbs/database.js');
|
|
2
|
-
|
|
3
|
-
class sorla{
|
|
4
|
-
/**
|
|
5
|
-
* Constructs class Sorla to manage databases
|
|
6
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
* @param
|
|
9
|
-
* @return void
|
|
10
|
-
*/
|
|
11
|
-
constructor()
|
|
12
|
-
{
|
|
13
|
-
this._dbs = [];
|
|
14
|
-
this._selectedDb = null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Search a database`s position in the list of databases by its name and mark it as selected
|
|
19
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
20
|
-
* @version
|
|
21
|
-
* @param
|
|
22
|
-
* @return
|
|
23
|
-
**/
|
|
24
|
-
_findDbIndex(name)
|
|
25
|
-
{
|
|
26
|
-
return this._dbs.findIndex(db => db.name == name);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Verify if a database name already exists in the list of databases
|
|
31
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
32
|
-
* @version 1.0.0
|
|
33
|
-
* @param string name
|
|
34
|
-
* @return boolean
|
|
35
|
-
*/
|
|
36
|
-
dbExists(name)
|
|
37
|
-
{
|
|
38
|
-
return this._findDbIndex(name) > -1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Mark a database as selected
|
|
43
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
44
|
-
* @version 1.0.0
|
|
45
|
-
* @param
|
|
46
|
-
* @return
|
|
47
|
-
**/
|
|
48
|
-
_selectDb(pos)
|
|
49
|
-
{
|
|
50
|
-
if(!this._dbs.hasOwnProperty(pos))
|
|
51
|
-
{
|
|
52
|
-
throw new Error('Database does not exists');
|
|
53
|
-
}
|
|
54
|
-
this._selectedDb = this._dbs[pos];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Creates a new database
|
|
59
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
60
|
-
* @version 1.0.0
|
|
61
|
-
* @param string name
|
|
62
|
-
* @return int "The position of the new database in the list of databases"
|
|
63
|
-
**/
|
|
64
|
-
createDb(name)
|
|
65
|
-
{
|
|
66
|
-
if(this.dbExists(name))
|
|
67
|
-
{
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let pos = this._dbs.length;
|
|
72
|
-
this._dbs.push(new database(name));
|
|
73
|
-
return pos;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Selects a database by its name or creates a new one if it does not exists and then selects it
|
|
78
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
79
|
-
* @version 1.0.0
|
|
80
|
-
* @param string name
|
|
81
|
-
* @return void
|
|
82
|
-
**/
|
|
83
|
-
useDb(name)
|
|
84
|
-
{
|
|
85
|
-
let pos = null;
|
|
86
|
-
if(!this.dbExists(name))
|
|
87
|
-
{
|
|
88
|
-
pos = this.createDb(name);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this._selectDb(pos === null ? this._findDbIndex(name) : pos);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Get the number of created databases
|
|
96
|
-
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
97
|
-
* @version 1.0.0
|
|
98
|
-
* @param
|
|
99
|
-
* @return int
|
|
100
|
-
**/
|
|
101
|
-
countDb()
|
|
102
|
-
{
|
|
103
|
-
return this._dbs.length;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Return selected db
|
|
108
|
-
* @author Anderson Arruda < anderson@sysborg.com.br >
|
|
109
|
-
* @version 1.0.0
|
|
110
|
-
* @param
|
|
111
|
-
* @return instanceof database
|
|
112
|
-
**/
|
|
113
|
-
get db()
|
|
114
|
-
{
|
|
115
|
-
return this._selectedDb;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = sorla;
|
|
120
|
-
if(typeof window !== 'undefined')
|
|
121
|
-
{
|
|
122
|
-
window.sorla = sorla;
|
|
1
|
+
const database = require('./dbs/database.js');
|
|
2
|
+
|
|
3
|
+
class sorla{
|
|
4
|
+
/**
|
|
5
|
+
* Constructs class Sorla to manage databases
|
|
6
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @param
|
|
9
|
+
* @return void
|
|
10
|
+
*/
|
|
11
|
+
constructor()
|
|
12
|
+
{
|
|
13
|
+
this._dbs = [];
|
|
14
|
+
this._selectedDb = null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Search a database`s position in the list of databases by its name and mark it as selected
|
|
19
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
20
|
+
* @version
|
|
21
|
+
* @param
|
|
22
|
+
* @return
|
|
23
|
+
**/
|
|
24
|
+
_findDbIndex(name)
|
|
25
|
+
{
|
|
26
|
+
return this._dbs.findIndex(db => db.name == name);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Verify if a database name already exists in the list of databases
|
|
31
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
32
|
+
* @version 1.0.0
|
|
33
|
+
* @param string name
|
|
34
|
+
* @return boolean
|
|
35
|
+
*/
|
|
36
|
+
dbExists(name)
|
|
37
|
+
{
|
|
38
|
+
return this._findDbIndex(name) > -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Mark a database as selected
|
|
43
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
44
|
+
* @version 1.0.0
|
|
45
|
+
* @param
|
|
46
|
+
* @return
|
|
47
|
+
**/
|
|
48
|
+
_selectDb(pos)
|
|
49
|
+
{
|
|
50
|
+
if(!this._dbs.hasOwnProperty(pos))
|
|
51
|
+
{
|
|
52
|
+
throw new Error('Database does not exists');
|
|
53
|
+
}
|
|
54
|
+
this._selectedDb = this._dbs[pos];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new database
|
|
59
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
60
|
+
* @version 1.0.0
|
|
61
|
+
* @param string name
|
|
62
|
+
* @return int "The position of the new database in the list of databases"
|
|
63
|
+
**/
|
|
64
|
+
createDb(name)
|
|
65
|
+
{
|
|
66
|
+
if(this.dbExists(name))
|
|
67
|
+
{
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let pos = this._dbs.length;
|
|
72
|
+
this._dbs.push(new database(name));
|
|
73
|
+
return pos;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Selects a database by its name or creates a new one if it does not exists and then selects it
|
|
78
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
79
|
+
* @version 1.0.0
|
|
80
|
+
* @param string name
|
|
81
|
+
* @return void
|
|
82
|
+
**/
|
|
83
|
+
useDb(name)
|
|
84
|
+
{
|
|
85
|
+
let pos = null;
|
|
86
|
+
if(!this.dbExists(name))
|
|
87
|
+
{
|
|
88
|
+
pos = this.createDb(name);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this._selectDb(pos === null ? this._findDbIndex(name) : pos);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the number of created databases
|
|
96
|
+
* @author Anderson Arruda < andmarruda@gmail.com >
|
|
97
|
+
* @version 1.0.0
|
|
98
|
+
* @param
|
|
99
|
+
* @return int
|
|
100
|
+
**/
|
|
101
|
+
countDb()
|
|
102
|
+
{
|
|
103
|
+
return this._dbs.length;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Return selected db
|
|
108
|
+
* @author Anderson Arruda < anderson@sysborg.com.br >
|
|
109
|
+
* @version 1.0.0
|
|
110
|
+
* @param
|
|
111
|
+
* @return instanceof database
|
|
112
|
+
**/
|
|
113
|
+
get db()
|
|
114
|
+
{
|
|
115
|
+
return this._selectedDb;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = sorla;
|
|
120
|
+
if(typeof window !== 'undefined')
|
|
121
|
+
{
|
|
122
|
+
window.sorla = sorla;
|
|
123
123
|
}
|
package/src/utils.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
class utils
|
|
2
|
-
{
|
|
3
|
-
/**
|
|
4
|
-
* Get a uuid v4 string
|
|
5
|
-
* @author Anderson Arruda < anderson@sysborg.com.br >
|
|
6
|
-
* @version 1.0.0
|
|
7
|
-
* @param
|
|
8
|
-
* @return string
|
|
9
|
-
**/
|
|
10
|
-
get uuid()
|
|
11
|
-
{
|
|
12
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c)
|
|
13
|
-
{
|
|
14
|
-
let r = Math.random() * 16 | 0,
|
|
15
|
-
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
16
|
-
|
|
17
|
-
return v.toString(16);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get data using dots to access subfields
|
|
23
|
-
* @param object data
|
|
24
|
-
* @param string field
|
|
25
|
-
*/
|
|
26
|
-
getDotData(data, field)
|
|
27
|
-
{
|
|
28
|
-
let fields = field.split('.');
|
|
29
|
-
|
|
30
|
-
fields.forEach(field => {
|
|
31
|
-
if(typeof data[field] !== 'undefined')
|
|
32
|
-
{
|
|
33
|
-
data = data[field];
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
class utils
|
|
2
|
+
{
|
|
3
|
+
/**
|
|
4
|
+
* Get a uuid v4 string
|
|
5
|
+
* @author Anderson Arruda < anderson@sysborg.com.br >
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @param
|
|
8
|
+
* @return string
|
|
9
|
+
**/
|
|
10
|
+
get uuid()
|
|
11
|
+
{
|
|
12
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c)
|
|
13
|
+
{
|
|
14
|
+
let r = Math.random() * 16 | 0,
|
|
15
|
+
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
16
|
+
|
|
17
|
+
return v.toString(16);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get data using dots to access subfields
|
|
23
|
+
* @param object data
|
|
24
|
+
* @param string field
|
|
25
|
+
*/
|
|
26
|
+
getDotData(data, field)
|
|
27
|
+
{
|
|
28
|
+
let fields = field.split('.');
|
|
29
|
+
|
|
30
|
+
fields.forEach(field => {
|
|
31
|
+
if(typeof data[field] !== 'undefined')
|
|
32
|
+
{
|
|
33
|
+
data = data[field];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
41
|
module.exports = utils;
|
|
@@ -1,73 +1,75 @@
|
|
|
1
|
-
const chai = require('chai')
|
|
2
|
-
const expect = chai.expect
|
|
3
|
-
const faker = require('faker')
|
|
4
|
-
const sorla = require('../src/sorla.js')
|
|
5
|
-
|
|
6
|
-
describe('SORLA Collection Feature Test', () => {
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
this.srla = new sorla();
|
|
9
|
-
this.dbname = faker.random.word();
|
|
10
|
-
this.srla.createDb(this.dbname);
|
|
11
|
-
this.srla.useDb(this.dbname);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{name: '
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{name: '
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
const chai = require('chai')
|
|
2
|
+
const expect = chai.expect
|
|
3
|
+
const faker = require('faker')
|
|
4
|
+
const sorla = require('../src/sorla.js')
|
|
5
|
+
|
|
6
|
+
describe('SORLA Collection Feature Test', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
this.srla = new sorla();
|
|
9
|
+
this.dbname = faker.random.word();
|
|
10
|
+
this.srla.createDb(this.dbname);
|
|
11
|
+
this.srla.useDb(this.dbname);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
let sequence = 0;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
// random words repeat or clash with database properties ("name"), so make them unique
|
|
17
|
+
this.collectionName = `collection_${++sequence}`;
|
|
18
|
+
this.srla.db.createCollection(this.collectionName);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('Create a single document inside of a collection and check by length', () => {
|
|
22
|
+
this.srla.db[this.collectionName].insertOne({name: 'Anderson'});
|
|
23
|
+
expect(this.srla.db[this.collectionName].count()).to.equal(1);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('create multiple documents and check by length', () => {
|
|
27
|
+
this.srla.db[this.collectionName].insertMany([
|
|
28
|
+
{name: 'Anderson'},
|
|
29
|
+
{name: 'Arruda'},
|
|
30
|
+
{name: 'Sorla'}
|
|
31
|
+
]);
|
|
32
|
+
expect(this.srla.db[this.collectionName].count()).to.equal(3);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('create a document with prohibited character $', () => {
|
|
36
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', $test: '123'})).to.throw();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('create a document with prohibited character .', () => {
|
|
40
|
+
expect(() => this.srla.db[this.collectionName].insertOne({"name.name": 'Anderson', test: {test: '123'}})).to.throw();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('create a document with prohibited character . inside of an array', () => {
|
|
44
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', test: [{"test.number": '123'}, {"test.number": '123'}]})).to.throw();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('create a document with prohibited character . inside of an object', () => {
|
|
48
|
+
expect(() => this.srla.db[this.collectionName].insertOne({name: 'Anderson', test: {"test.number": '123'}})).to.throw();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/*it('get a document by his subfield using test.inscription', () => {
|
|
52
|
+
this.srla.db[this.collectionName].insertMany([
|
|
53
|
+
{name: 'Anderson', test: {inscription: 123}},
|
|
54
|
+
{name: 'Arruda', test: {inscription: 321}},
|
|
55
|
+
{name: 'Sorla', test: {inscription: 213}}
|
|
56
|
+
]);
|
|
57
|
+
expect(this.srla.db[this.collectionName].findOne({'test.inscription': 123}).length).to.equal(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('Try to create a document without beeing a valid object', () => {
|
|
61
|
+
expect(() => this.srla.db[this.collectionName].insertOne('Anderson')).to.throw();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('Try to create a document with array', () => {
|
|
65
|
+
expect(() => this.srla.db[this.collectionName].insertOne(['Anderson'])).to.throw();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Try to create many documents without beeing a valid array', () => {
|
|
69
|
+
expect(() => this.srla.db[this.collectionName].insertMany('Anderson')).to.throw();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('Try to create many documents without having valid object', () => {
|
|
73
|
+
expect(() => this.srla.db[this.collectionName].insertMany([{test: '123', }, 'anderson'])).to.throw();
|
|
74
|
+
});*/
|
|
73
75
|
});
|