@axiosleo/orm-mysql 0.6.2 → 0.7.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/index.d.ts CHANGED
@@ -79,6 +79,8 @@ export declare class Query {
79
79
 
80
80
  whereConditions(...condition: WhereOptions[]): this;
81
81
 
82
+ groupWhere(...condition: WhereOptions[]): this;
83
+
82
84
  orWhere(key: string | null, opt: OptType, value: ConditionValueType | WhereOptions[]): this;
83
85
 
84
86
  andWhere(key: string | null, opt: OptType, value: ConditionValueType | WhereOptions[]): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/builder.js CHANGED
@@ -216,6 +216,12 @@ class Builder {
216
216
  let sql = typeof prefix === 'undefined' ? 'WHERE ' : prefix;
217
217
  if (conditions.length) {
218
218
  sql += `${conditions.map((c) => {
219
+ if (typeof c.key === 'undefined') {
220
+ c.key = null;
221
+ }
222
+ if (typeof c.value === 'undefined') {
223
+ c.value = null;
224
+ }
219
225
  if (c.key === null && c.value === null) {
220
226
  return ` ${c.opt} `;
221
227
  }
package/src/hook.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const EventEmitter = require('events');
4
4
 
5
- const events = new Map(); // event tree
5
+ const events = {}; // event tree
6
6
  const hook = new EventEmitter();
7
7
 
8
8
  const push = (callback, trace = []) => {
@@ -15,10 +15,10 @@ const push = (callback, trace = []) => {
15
15
  curr_key = '*';
16
16
  }
17
17
  event_name_items.push(curr_key);
18
- if (!curr.has(curr_key)) {
19
- curr.set(curr_key, new Map());
18
+ if (!curr[curr_key]) {
19
+ curr[curr_key] = {};
20
20
  }
21
- curr = curr.get(curr_key);
21
+ curr = curr[curr_key];
22
22
  step++;
23
23
  }
24
24
  let event_name = event_name_items.join('::');
@@ -33,6 +33,14 @@ const pushEvent = (options = {}) => {
33
33
  return { event_name, label, table, opt, callback };
34
34
  };
35
35
 
36
+ /**
37
+ * @param {Map} curr
38
+ * @param {*} trace
39
+ * @param {*} step
40
+ * @param {*} paths
41
+ * @param {*} args
42
+ * @returns
43
+ */
36
44
  const eventRecur = (curr, trace, step, paths, args) => {
37
45
  if (step === trace.length) {
38
46
  hook.emit(paths.join('::'), ...args);
@@ -41,7 +49,7 @@ const eventRecur = (curr, trace, step, paths, args) => {
41
49
  const t = trace[step];
42
50
  if (curr['*']) {
43
51
  paths[step] = '*';
44
- eventRecur(curr[t], trace, step + 1, paths, args);
52
+ eventRecur(curr['*'], trace, step + 1, paths, args);
45
53
  }
46
54
  if (curr[t]) {
47
55
  paths[step] = t;
package/src/query.js CHANGED
@@ -69,6 +69,18 @@ class Query {
69
69
  return this;
70
70
  }
71
71
 
72
+ groupWhere(...conditions) {
73
+ if (!conditions.length) {
74
+ return this;
75
+ }
76
+ const condition = { key: null, opt: 'group', value: [] };
77
+ conditions.forEach((c) => {
78
+ condition.value.push(c);
79
+ });
80
+ this.options.conditions.push(condition);
81
+ return this;
82
+ }
83
+
72
84
  orWhere(key, opt, value) {
73
85
  if (!this.options.conditions.length) {
74
86
  throw new Error('At least one where condition is required');