molly-db 1.0.32 → 1.0.40

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/main.js CHANGED
@@ -20,7 +20,7 @@ class molly_db{
20
20
  this.path = opt.path.replace( /^\./,process.cwd() );
21
21
  this.threads = opt.threads || 1;
22
22
  this.import = opt.import || '';
23
- this.time = opt.saveTime || .5;
23
+ this.time = opt.saveTime || .1;
24
24
  return require(`${__dirname}/module/_worker_.js`)(this);
25
25
  }
26
26
  }
package/module/_api_.js CHANGED
@@ -97,11 +97,11 @@ async function addTable( _params ){
97
97
  }
98
98
  }
99
99
 
100
- /*await save( _params )*/ return [{
100
+ /*await save( _params )*/ return {
101
101
  status: 'table added',
102
102
  database: _params.db,
103
103
  table: _params.table,
104
- }];
104
+ };
105
105
 
106
106
  } catch(e) { return parseError(e) }
107
107
  }
@@ -123,11 +123,11 @@ async function removeTable( _params ){
123
123
  }
124
124
  }
125
125
 
126
- /*await save( _params )*/ return [{
126
+ /*await save( _params )*/ return {
127
127
  status: 'table removed',
128
128
  database: _params.db,
129
129
  table: _params.table,
130
- }];
130
+ };
131
131
 
132
132
  } catch(e) { return parseError(e) }
133
133
  }
@@ -147,10 +147,10 @@ async function addDB( _params ){
147
147
  tables: [], name: _params.db,
148
148
  }); db[_params.db] = new Array();
149
149
 
150
- /*await save( _params )*/ return [{
150
+ /*await save( _params )*/ return {
151
151
  database: _params.db,
152
152
  status: 'DB added'
153
- }];
153
+ };
154
154
 
155
155
  } catch(e) { return parseError(e) }
156
156
  }
@@ -175,11 +175,11 @@ async function removeDB( _params ){
175
175
  }
176
176
  }
177
177
 
178
- /*await save( _params )*/ return [{
178
+ /*await save( _params )*/ return {
179
179
  database: _params.db,
180
180
  table: _params.table,
181
181
  status: 'DB deleted'
182
- }];
182
+ };
183
183
 
184
184
  } catch(e) { return parseError(e) }
185
185
  }
@@ -202,11 +202,11 @@ async function modifyDB( _name, _table ){
202
202
 
203
203
  /* --------------------------------------------------------------------------------------- */
204
204
 
205
- async function saveAll( _params ){
205
+ async function saveAll(){
206
206
  try{for( var i in db['_init_'] ){ for( var j in db['_init_'][i] ){
207
207
  const {name,tables} = db['_init_'][i][j];
208
208
  for( var k in tables )
209
209
  await modifyDB(name,tables[k])
210
- }} return parseData([]);
211
- } catch(e) { return parseError(e) }
210
+ }} return { status: 'DB Saved' };
211
+ } catch(e) { console.log(e); return parseError(e) }
212
212
  }
package/module/_app_.js CHANGED
@@ -146,41 +146,40 @@ async function save( _params ){
146
146
  try{
147
147
 
148
148
  body = await getBody();
149
- params = await validate(params);
149
+ if( api.pathname == '/saveAll' )
150
+ return json( await saveAll() );
151
+ params = await validate(params);
150
152
 
151
153
  /* Find Api */
152
- if( api.pathname == '/list' ) json( await list(params) )
153
- else if( api.pathname == '/hash' ) json( await hash(params) )
154
- else if( api.pathname == '/match' ) json( await match(params) )
155
- else if( api.pathname == '/update' ) json( await update(params) )
156
-
157
- else if( api.pathname == '/index' ) json( await indexOf(params) )
158
- else if( api.pathname == '/length' ) json( await lengthOf(params) )
159
-
160
- /* Save Api */
161
- else if( api.pathname == '/save' ) json( await save(params) )
162
- else if( api.pathname == '/remove' ) json( await remove(params) )
163
- else if( api.pathname == '/refresh' ) json( await refresh(params) )
164
- else if( api.pathname == '/saveAll' ) json( await saveAll(params) )
165
-
166
- /* Remove Api */
167
- else if( api.pathname == '/pop' ) json( await pop(params) )
168
- else if( api.pathname == '/shift' ) json( await shift(params) )
169
-
170
- /* Modify Api */
171
- else if( api.pathname == '/push' ) json( await push(params) )
172
- else if( api.pathname == '/splice' ) json( await splice(params) )
173
- else if( api.pathname == '/unshift' ) json( await unshift(params) )
174
-
175
- /* Modify Table Api */
176
- else if( api.pathname == '/addDB' ) json( await addDB(params) )
177
- else if( api.pathname == '/removeDB' ) json( await removeDB(params) )
178
-
179
- /* Modify Table Api */
180
- else if( api.pathname == '/addTable' ) json( await addTable(params) )
181
- else if( api.pathname == '/removeTable' ) json( await removeTable(params) )
182
-
183
- else error(parseError('Oops something went wrong'));
154
+ switch( api.pathname ){
155
+
156
+ case '/pop': return json( await pop(params) );
157
+ case '/shift': return json( await shift(params) );
158
+
159
+ case '/list': return json( await list(params) );
160
+ case '/hash': return json( await hash(params) );
161
+ case '/match': return json( await match(params) );
162
+ case '/update': return json( await update(params) );
163
+
164
+ case '/push': return json( await push(params) );
165
+ case '/slice': return json( await splice(params) );
166
+ case 'unshift': return json( await unshift(params) );
167
+
168
+ case '/save': return json( await save(params) );
169
+ case '/remove': return json( await remove(params) );
170
+ case '/refresh': return json( await refresh(params) );
171
+
172
+ case '/index': return json( await indexOf(params) );
173
+ case '/length': return json( await lengthOf(params) );
174
+
175
+ case '/addDB': return json( await addDB(params) );
176
+ case '/removeDB': return json( await removeDB(params) );
177
+ case '/addTable': return json( await addTable(params) );
178
+ case '/removeTable':return json( await removeTable(params) );
179
+
180
+ default: return error(parseError('Oops something went wrong'));
181
+
182
+ }
184
183
 
185
184
  } catch(e) { error(parseError(e)); }
186
185
  })();
@@ -14,25 +14,20 @@ const db = new Object();
14
14
  const api_script = fs.readFileSync(`${__dirname}/_api_.js`).toString();
15
15
  const app_script = fs.readFileSync(`${__dirname}/_app_.js`).toString();
16
16
  const init_script = fs.readFileSync(`${__dirname}/_init_.js`).toString();
17
- //const importDB_script = fs.readFileSync(`${__dirname}/_importDB.js`).toString();
18
17
 
19
18
  /* --------------------------------------------------------------------------------------- */
20
19
 
21
20
  async function _init_(){ await eval(`try{ ${init_script} }catch(e){console.log(e)}`) }
22
- async function _importDB_(){ await eval(`try{ ${importDB_script} }catch(e){console.log(e)}`) }
23
21
  async function app(req,res){ await eval(`try{ ${api_script} \n ${app_script} }catch(e){console.log(e)}`) }
24
22
 
25
23
  /* --------------------------------------------------------------------------------------- */
26
24
  function saveTimeout(){
27
25
  time = process.mollyDB.time * 3600000;
28
26
  setTimeout(() => {
29
- if( db._update_ == true ){
30
- const api = url.format({
31
- path: '/saveAll?db=&table=',
32
- port: process.mollyDB.port,
33
- host: 'http://127.0.0.1',
34
- }); fetch(api).then().catch();
35
- db._update_ = false;
27
+ if( db._update_ ){db._update_ = false;
28
+ const port = process.mollyDB.port;
29
+ const api = `http://127.0.0.1:${port}/saveAll`;
30
+ fetch(api).then(()=>{}).catch(()=>{});
36
31
  }
37
32
  }, time);
38
33
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "license": "MIT",
3
3
  "main": "main.js",
4
4
  "name": "molly-db",
5
- "version": "1.0.32",
5
+ "version": "1.0.40",
6
6
  "author": "bececrazy",
7
7
  "scripts": { "start": "node main" },
8
8
  "repository": "https://github.com/EDBC-REPO-NPM/Molly-db",