molly-db 1.0.24 → 1.0.27

Sign up to get free protection for your applications and to get access to all the features.
package/main.js CHANGED
@@ -15,13 +15,12 @@ function config( _config ) {
15
15
  /* --------------------------------------------------------------------------------------- */
16
16
 
17
17
  class molly_db{
18
-
19
18
  constructor( opt ){ if( opt.pass )
20
19
  this.pass = opt.pass; this.port = opt.port || 27017;
21
20
  this.path = opt.path.replace( /^\./,process.cwd() );
21
+ this.threads = opt.threads || 1;
22
22
  return require(`${__dirname}/module/_worker_.js`)(this);
23
23
  }
24
-
25
24
  }
26
25
 
27
26
  /* --------------------------------------------------------------------------------------- */
package/module/_init_.js CHANGED
@@ -6,9 +6,7 @@ function fillDB( _db, _table, _path ){
6
6
 
7
7
  if( (/^http/).test(_path) ){ try{
8
8
  const stream = await fetch(_path,{responseType:'stream'});
9
- _itr = readline.createInterface({
10
- input: stream.data
11
- })
9
+ _itr = readline.createInterface({ input: stream.data });
12
10
  } catch(e) { console.log(`error reading ${_path}`); return response(); }}
13
11
 
14
12
  else if( fs.existsSync(_path) )
@@ -10,8 +10,8 @@ const fs = require('fs');
10
10
 
11
11
  /* --------------------------------------------------------------------------------------- */
12
12
 
13
- let query;
14
13
  const db = new Object();
14
+ let query;
15
15
 
16
16
  /* --------------------------------------------------------------------------------------- */
17
17
 
@@ -31,19 +31,22 @@ function app(req,res){
31
31
 
32
32
  module.exports = (args)=>{ query = args;
33
33
  return new Promise((response,reject)=>{
34
- if (cluster.isPrimary) { const worker = cluster.fork();
34
+
35
+ if ( cluster.isPrimary ) { for ( let i=query.threads; i--; ) {
36
+ const worker = cluster.fork();
37
+ worker.on('message', (msg)=>{ console.log(msg); response(); });
35
38
  cluster.on('exit', (worker, code, signal) => { cluster.fork();
36
39
  console.log(`worker ${worker.process.pid} died`);
37
- }); worker.on('message', (msg)=>{ console.log(msg); response(); });
38
- worker.on('exit', (msg)=>{ reject(msg); });
39
- } else {
40
+ }); worker.on('exit', (msg)=>{ reject(msg); });
41
+ }} else {
40
42
  http.createServer( app ).listen( query.port,()=>{
41
43
  _init_().then(()=>{ process.send({
42
44
  workerID: process.pid, port: query.port,
43
45
  protocol: 'HTTP', status: 'started',
44
46
  })}).catch(e=>{ console.log(e); });
45
- });
47
+ });
46
48
  }
49
+
47
50
  });
48
51
  }
49
52
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "MIT",
3
3
  "main": "main.js",
4
- "version": "1.0.24",
4
+ "version": "1.0.27",
5
5
  "name": "molly-db",
6
6
  "author": "bececrazy",
7
7
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "crypto-js": "^4.1.1",
13
13
  "fs": "^0.0.1-security",
14
- "molly-fetch": "^1.0.14"
14
+ "molly-fetch": "^1.0.16"
15
15
  },
16
16
  "description": "Molly-db is a free and open source library for nodejs that allow you create a lightweight encrypted database using Json files",
17
17
  "keywords": [