@axiosleo/orm-mysql 0.11.7 → 0.11.9
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/bin/orm-mysql.js +1 -1
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/builder.js +17 -1
- package/src/query.js +6 -0
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export type QueryOperatorOptions = QueryOperatorBaseOptions & {
|
|
|
74
74
|
pageLimit?: number;
|
|
75
75
|
pageOffset?: number;
|
|
76
76
|
tables: TableOption[];
|
|
77
|
+
forceIndex: string | null;
|
|
77
78
|
operator: OperatorType | null;
|
|
78
79
|
data: any | null;
|
|
79
80
|
groupField: string[];
|
|
@@ -447,6 +448,7 @@ type FieldType =
|
|
|
447
448
|
interface ColumnItem {
|
|
448
449
|
type: FieldType,
|
|
449
450
|
length?: number,
|
|
451
|
+
precision?: number,
|
|
450
452
|
unsigned?: boolean,
|
|
451
453
|
allowNull?: boolean,
|
|
452
454
|
default?: string | number | boolean | null | 'timestamp',
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -68,6 +68,7 @@ class Builder {
|
|
|
68
68
|
throw new Error('having is not allowed without "GROUP BY"');
|
|
69
69
|
}
|
|
70
70
|
emit(tmp, `SELECT ${attrs.length ? attrs.map((a) => this._buildFieldKey(a)).join(',') : '*'} FROM ${this._buildTables(options.tables)}`);
|
|
71
|
+
emit(tmp, this._buildForceIndex(options.forceIndex || null));
|
|
71
72
|
emit(tmp, this._buildJoins(options.joins));
|
|
72
73
|
emit(tmp, this._buildCondition(options.conditions));
|
|
73
74
|
emit(tmp, this._buildGroupField(options.groupField));
|
|
@@ -81,6 +82,13 @@ class Builder {
|
|
|
81
82
|
return sql;
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
_buildForceIndex(forceIndex) {
|
|
86
|
+
if (!forceIndex) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
return `FORCE INDEX(${forceIndex})`;
|
|
90
|
+
}
|
|
91
|
+
|
|
84
92
|
_insertOperator(options) {
|
|
85
93
|
let tmp = [];
|
|
86
94
|
const { fields, sqlStr } = this._buildValues(options.data);
|
|
@@ -100,6 +108,7 @@ class Builder {
|
|
|
100
108
|
}
|
|
101
109
|
const fields = this._buildValue(options.data);
|
|
102
110
|
emit(tmp, `UPDATE ${this._buildTables(options.tables)}`);
|
|
111
|
+
emit(tmp, this._buildForceIndex(options.forceIndex || null));
|
|
103
112
|
emit(tmp, `SET ${fields.map((f) => `\`${f}\` = ?`).join(',')}`);
|
|
104
113
|
if (!options.conditions.length) {
|
|
105
114
|
throw new Error('At least one condition is required for update operation');
|
|
@@ -675,6 +684,7 @@ class ManageSQLBuilder extends Builder {
|
|
|
675
684
|
type: 'required|string',
|
|
676
685
|
onUpdate: 'string',
|
|
677
686
|
length: 'integer',
|
|
687
|
+
precision: 'integer',
|
|
678
688
|
comment: 'string',
|
|
679
689
|
allowNull: 'boolean',
|
|
680
690
|
autoIncrement: 'boolean',
|
|
@@ -688,13 +698,19 @@ class ManageSQLBuilder extends Builder {
|
|
|
688
698
|
}
|
|
689
699
|
let str = `\`${options.name}\` ${type}`;
|
|
690
700
|
if (typeof options.length !== 'undefined') {
|
|
691
|
-
|
|
701
|
+
if (type === 'DECIMAL') {
|
|
702
|
+
str += `(${options.length}, ${options.precision || 6})`;
|
|
703
|
+
} else {
|
|
704
|
+
str += `(${options.length})`;
|
|
705
|
+
}
|
|
692
706
|
} else if (type === 'INT') {
|
|
693
707
|
str += '(11)';
|
|
694
708
|
} else if (type === 'VARCHAR') {
|
|
695
709
|
str += '(255)';
|
|
696
710
|
} else if (type === 'TINYINT') {
|
|
697
711
|
str += '(4)';
|
|
712
|
+
} else if (type === 'DECIMAL') {
|
|
713
|
+
str += '(10, 6)';
|
|
698
714
|
}
|
|
699
715
|
if (options.allowNull === false || options.primaryKey === true) {
|
|
700
716
|
str += ' NOT NULL';
|
package/src/query.js
CHANGED
|
@@ -164,6 +164,7 @@ class Query extends QueryCondition {
|
|
|
164
164
|
conditions: [],
|
|
165
165
|
orders: [],
|
|
166
166
|
tables: [],
|
|
167
|
+
forceIndex: null,
|
|
167
168
|
attrs: [],
|
|
168
169
|
operator,
|
|
169
170
|
data: null,
|
|
@@ -189,6 +190,11 @@ class Query extends QueryCondition {
|
|
|
189
190
|
return this;
|
|
190
191
|
}
|
|
191
192
|
|
|
193
|
+
force(indexName) {
|
|
194
|
+
this.options.forceIndex = indexName;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
|
|
192
198
|
keys(...keys) {
|
|
193
199
|
this.options.keys = keys;
|
|
194
200
|
return this;
|