@axiosleo/orm-mysql 0.2.1 → 0.2.3

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/.env ADDED
@@ -0,0 +1,6 @@
1
+ [mysql]
2
+ MYSQL_HOST = "rm-bp1a906h4019pldm6io.mysql.rds.aliyuncs.com"
3
+ MYSQL_USER = "kms"
4
+ MYSQL_PASS = "bmPWuq_vJgupdL9"
5
+ MYSQL_PORT = 3306
6
+ MYSQL_DB = "factory-cloud-dev"
package/.eslintrc CHANGED
@@ -103,7 +103,8 @@
103
103
  "it": true,
104
104
  "before": true,
105
105
  "after": true,
106
- "beforeEach": true
106
+ "beforeEach": true,
107
+ "afterEach": true
107
108
  },
108
109
  "parserOptions": {
109
110
  "ecmaVersion": 2018,
@@ -111,4 +112,4 @@
111
112
  "ecmaFeatures": {}
112
113
  },
113
114
  "extends": "eslint:recommended"
114
- }
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/runtimes/test.js CHANGED
@@ -1,25 +1,32 @@
1
1
  'use strict';
2
2
 
3
3
  const { debug } = require('@axiosleo/cli-tool');
4
- const mm = require('mm');
5
- // const expect = require('chai').expect;
6
- const mysql = require('mysql2');
7
- const { QueryHandler, Query } = require('../src/operator');
4
+ // const mm = require('mm');
5
+ // // const expect = require('chai').expect;
6
+ // const mysql = require('mysql2');
7
+ const {
8
+ // QueryHandler,
9
+ Query
10
+ } = require('../src/operator');
8
11
 
9
- mm(mysql, 'createConnection', (options) => {
10
- return {
12
+ // mm(mysql, 'createConnection', (options) => {
13
+ // return {
11
14
 
12
- };
13
- });
15
+ // };
16
+ // });
14
17
 
15
- const conn = mysql.createConnection({});
16
- const hanlder = new QueryHandler(conn);
17
- // const query = hanlder.table('meta_items', 'u');
18
+ // const conn = mysql.createConnection({});
19
+ // const hanlder = new QueryHandler(conn);
20
+ // // const query = hanlder.table('meta_items', 'u');
18
21
 
19
- const query = hanlder.table('meta_items');
20
- const subQuery = new Query('select');
21
- subQuery.table('meta_items').attr('item_code').groupBy('item_code').having('COUNT(*)', '>', 1);
22
- const res = query.where('item_code', subQuery, 'IN').buildSql('select');
22
+ // const query = hanlder.table('meta_items');
23
+ // const subQuery = new Query('select');
24
+ // subQuery.table('meta_items').attr('item_code').groupBy('item_code').having('COUNT(*)', '>', 1);
25
+ // const res = query.where('item_code', subQuery, 'IN').buildSql('select');
23
26
  // expect(res.sql).to.be.equal('SELECT * FROM `users` AS `u` WHERE `name` IN (SELECT * FROM `users`)');
24
27
 
25
- debug.log(res);
28
+ // debug.log(res);
29
+
30
+ const q = new Query();
31
+
32
+ debug.log(typeof q, q instanceof Query);
package/src/query.js CHANGED
@@ -11,7 +11,8 @@ class Query {
11
11
  operator,
12
12
  data: null,
13
13
  groupField: [],
14
- having: []
14
+ having: [],
15
+ joins: []
15
16
  };
16
17
  }
17
18
 
@@ -80,6 +81,9 @@ class Query {
80
81
  }
81
82
 
82
83
  attr(...attr) {
84
+ if (!attr.length) {
85
+ return this;
86
+ }
83
87
  if (!this.options.attrs) {
84
88
  this.options.attrs = [];
85
89
  }
@@ -128,6 +132,15 @@ class Query {
128
132
  }
129
133
 
130
134
  join(table, alias, on, type) {
135
+ if (!alias) {
136
+ throw new Error('Alias is required');
137
+ }
138
+ if (!on) {
139
+ throw new Error('On is required');
140
+ }
141
+ if (['left', 'right', 'inner'].indexOf(type) === -1) {
142
+ throw new Error('Invalid join type : ' + type + '; only supported left, right, inner');
143
+ }
131
144
  this.options.joins.push({ table, alias, on, type });
132
145
  return this;
133
146
  }