molly-db 1.0.12 → 1.0.13

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/module/_init_.js CHANGED
@@ -9,16 +9,18 @@ function fillDB( _db, _table, _path ){
9
9
  _itr = readline.createInterface({
10
10
  input: stream.data
11
11
  });
12
+ }
12
13
 
13
- } else
14
+ else if( fs.existsSync(_path) )
14
15
  _itr = readline.createInterface({
15
16
  input: fs.createReadStream(_path)
16
17
  });
18
+
19
+ else return response();
17
20
 
18
- _itr.on('close',()=>{ response() });
19
21
  _itr.on('line',(line)=>{
20
22
  db[_db][_table].push(crypto.decrypt( line,query.pass ));
21
- });
23
+ }); _itr.on('close',()=>{ response() });
22
24
 
23
25
  });
24
26
  }
@@ -50,8 +52,7 @@ function fillDB( _db, _table, _path ){
50
52
  for( var j in DB.tables ){
51
53
  const table = DB.tables[j];
52
54
  const path = `${db._path_}/${table}.json`;
53
- db[name][table] = new Array();
54
- await fillDB( name,table,path );
55
+ db[name][table] = new Array(); await fillDB( name,table,path );
55
56
  }
56
57
 
57
58
  }
@@ -151,6 +151,16 @@ function pop( _params ){
151
151
 
152
152
  /* --------------------------------------------------------------------------------------- */
153
153
 
154
+ function lengthOf( _params ){ return db[_params.db][_params.table].length; }
155
+ function indexOf( _params ){
156
+ return db[_params.db][_params.table].indexOf(x=>{
157
+ const regex = new RegExp(_params.target,'gi');
158
+ return regex.test(x);
159
+ });
160
+ }
161
+
162
+ /* --------------------------------------------------------------------------------------- */
163
+
154
164
  async function push( _params ){
155
165
 
156
166
  db[_params.db][_params.table].push( ...body );
@@ -360,6 +370,9 @@ function save( _params ){
360
370
  else if( api.pathname == '/match' ) json( await match(params) )
361
371
  else if( api.pathname == '/update' ) json( await update(params) )
362
372
 
373
+ else if( api.pathname == '/index' ) json( await indexOf(params) )
374
+ else if( api.pathname == '/lengt' ) json( await lengthOf(params) )
375
+
363
376
  /* Save Api */
364
377
  else if( api.pathname == '/save' ) json( await save(params) )
365
378
  else if( api.pathname == '/remove' ) json( await remove(params) )
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "MIT",
3
3
  "main": "main.js",
4
- "version": "1.0.12",
4
+ "version": "1.0.13",
5
5
  "name": "molly-db",
6
6
  "author": "bececrazy",
7
7
  "scripts": {