hola-server 0.5.2 → 0.5.4
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/db/db.js +8 -4
- package/db/entity.js +3 -1
- package/http/express.js +1 -6
- package/index.js +5 -3
- package/package.json +1 -1
package/db/db.js
CHANGED
|
@@ -131,7 +131,7 @@ const bulk_update = async (col, items, attrs) => {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
class DB {
|
|
134
|
-
constructor(url, poolSize) {
|
|
134
|
+
constructor(url, poolSize, callback) {
|
|
135
135
|
if (!url) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
@@ -143,6 +143,10 @@ class DB {
|
|
|
143
143
|
log_error(LOG_DB, err);
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
|
+
|
|
147
|
+
this.db.on('connect', function () {
|
|
148
|
+
callback && callback();
|
|
149
|
+
});
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/**
|
|
@@ -343,19 +347,19 @@ class DB {
|
|
|
343
347
|
}
|
|
344
348
|
}
|
|
345
349
|
|
|
346
|
-
let db_instance =
|
|
350
|
+
let db_instance = null;
|
|
347
351
|
|
|
348
352
|
/**
|
|
349
353
|
*
|
|
350
354
|
* @returns db instance of mongodb
|
|
351
355
|
*/
|
|
352
|
-
const get_db = () => {
|
|
356
|
+
const get_db = (callback) => {
|
|
353
357
|
if (db_instance && db_instance.db) {
|
|
354
358
|
return db_instance;
|
|
355
359
|
} else {
|
|
356
360
|
const mongo = get_settings().mongo;
|
|
357
361
|
|
|
358
|
-
db_instance = new DB(mongo.url, mongo.pool);
|
|
362
|
+
db_instance = new DB(mongo.url, mongo.pool, callback);
|
|
359
363
|
return db_instance;
|
|
360
364
|
}
|
|
361
365
|
};
|
package/db/entity.js
CHANGED
|
@@ -127,7 +127,9 @@ class Entity {
|
|
|
127
127
|
//refer field
|
|
128
128
|
const refer_entity = new Entity(get_entity_meta(search_field.ref));
|
|
129
129
|
const oids = await refer_entity.find_by_ref_value(value, { _id: 1 }, this.meta.collection);
|
|
130
|
-
if (oids.length
|
|
130
|
+
if (oids.length == 1) {
|
|
131
|
+
and_array.push({ [search_field.name]: oids.map(o => o._id + "")[0] });
|
|
132
|
+
} else if (oids.length > 1) {
|
|
131
133
|
and_array.push({ [search_field.name]: { "$in": oids.map(o => o._id + "") } });
|
|
132
134
|
}
|
|
133
135
|
} else {
|
package/http/express.js
CHANGED
|
@@ -68,9 +68,4 @@ const init_express_server = (base_dir, callback) => {
|
|
|
68
68
|
return app;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
module.exports = { init_express_server };
|
|
72
|
-
|
|
73
|
-
const str = "/monitor/635c7e6aecf2f40bf70feca9";
|
|
74
|
-
const exclude_urls = ["/monitor/.*?/"];
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
module.exports = { init_express_server };
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
const { get_db } = require('./db/db');
|
|
2
|
+
const { Entity } = require('./db/entity');
|
|
1
3
|
const { init_settings } = require('./setting');
|
|
2
|
-
const { init_express_server } = require('./http/express');
|
|
3
4
|
const { init_router } = require('./http/router');
|
|
5
|
+
const { init_express_server } = require('./http/express');
|
|
4
6
|
const { register_type, get_type } = require('./core/type');
|
|
5
7
|
const { EntityMeta, get_entity_meta } = require('./core/meta');
|
|
6
|
-
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
const array = require('./core/array');
|
|
9
11
|
const date = require('./core/date');
|
|
@@ -23,7 +25,7 @@ const { gen_i18n } = require('./tool/gen_i18n');
|
|
|
23
25
|
const { log_debug, log_info, log_warn, log_error, is_log_debug, is_log_info, is_log_warn, is_log_error, get_session_userid, oid_queries, oid_query } = require('./db/db');
|
|
24
26
|
|
|
25
27
|
module.exports = {
|
|
26
|
-
init_settings, init_express_server, init_router, register_type, get_type,
|
|
28
|
+
init_settings, init_express_server, init_router, register_type, get_type, get_db,
|
|
27
29
|
Entity, EntityMeta, get_entity_meta, array, date, file, number, obj, random, thread, validate, code, err, params, context, gridfs, gen_i18n,
|
|
28
30
|
log_debug, log_info, log_warn, log_error, is_log_debug, is_log_info, is_log_warn, is_log_error, get_session_userid, oid_queries, oid_query
|
|
29
31
|
};
|