@rdyl/node-mysql 0.0.3 → 0.0.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/CHANGELOG.md +1 -1
- package/dist/helper.js +519 -0
- package/dist/index.js +11 -1
- package/dist/interface.js +23 -0
- package/dist/meta.js +180 -92
- package/dist/utils.js +42 -15
- package/package.json +1 -1
- package/types/helper.d.ts +79 -0
- package/types/index.d.ts +6 -3
- package/types/interface.d.ts +40 -0
- package/types/meta.d.ts +22 -41
- package/types/utils.d.ts +7 -4
- package/dist/selector.js +0 -175
- package/types/selector.d.ts +0 -37
package/dist/selector.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.MysqlDeleter = exports.MysqlUpdater = exports.MysqlInserter = exports.MysqlSelector = void 0;
|
|
40
|
-
var meta_1 = require("./meta");
|
|
41
|
-
var utils_1 = require("./utils");
|
|
42
|
-
/** @description 查询数据 */
|
|
43
|
-
var MysqlSelector = /** @class */ (function () {
|
|
44
|
-
function MysqlSelector(_tableName) {
|
|
45
|
-
this._tableName = _tableName;
|
|
46
|
-
this.conditions = [];
|
|
47
|
-
this.options = new meta_1.Options();
|
|
48
|
-
}
|
|
49
|
-
Object.defineProperty(MysqlSelector.prototype, "sql", {
|
|
50
|
-
get: function () {
|
|
51
|
-
var _a = this, conditions = _a.conditions, options = _a.options;
|
|
52
|
-
if (conditions.length === 0) {
|
|
53
|
-
return '';
|
|
54
|
-
}
|
|
55
|
-
var target = 'SELECT * FROM $tableName\n';
|
|
56
|
-
conditions.forEach(function (ele) {
|
|
57
|
-
target = ele.connect(target);
|
|
58
|
-
});
|
|
59
|
-
return "".concat(target, "\n").concat(options.result, ";");
|
|
60
|
-
},
|
|
61
|
-
enumerable: false,
|
|
62
|
-
configurable: true
|
|
63
|
-
});
|
|
64
|
-
MysqlSelector.prototype.select = function (opts) {
|
|
65
|
-
this.conditions.push(new meta_1.Condition(opts));
|
|
66
|
-
return this;
|
|
67
|
-
};
|
|
68
|
-
MysqlSelector.prototype.limit = function (n) {
|
|
69
|
-
this.options.limit = n;
|
|
70
|
-
return this;
|
|
71
|
-
};
|
|
72
|
-
MysqlSelector.prototype.skip = function (n) {
|
|
73
|
-
this.options.skip = n;
|
|
74
|
-
return this;
|
|
75
|
-
};
|
|
76
|
-
MysqlSelector.prototype.sort = function (field, v) {
|
|
77
|
-
this.options.sort[field] = v;
|
|
78
|
-
return this;
|
|
79
|
-
};
|
|
80
|
-
/** @查询结果 */
|
|
81
|
-
MysqlSelector.prototype.result = function () {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
try {
|
|
85
|
-
}
|
|
86
|
-
catch (_b) { }
|
|
87
|
-
return [2 /*return*/];
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
return MysqlSelector;
|
|
92
|
-
}());
|
|
93
|
-
exports.MysqlSelector = MysqlSelector;
|
|
94
|
-
/** @description 插入数据 */
|
|
95
|
-
var MysqlInserter = /** @class */ (function () {
|
|
96
|
-
function MysqlInserter(_tableName) {
|
|
97
|
-
this._tableName = _tableName;
|
|
98
|
-
this.fields = [];
|
|
99
|
-
this.values = [];
|
|
100
|
-
}
|
|
101
|
-
Object.defineProperty(MysqlInserter.prototype, "_fieldSql", {
|
|
102
|
-
get: function () {
|
|
103
|
-
return "(".concat(this.fields.join(', '), ")");
|
|
104
|
-
},
|
|
105
|
-
enumerable: false,
|
|
106
|
-
configurable: true
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(MysqlInserter.prototype, "_valueSql", {
|
|
109
|
-
get: function () {
|
|
110
|
-
var _this = this;
|
|
111
|
-
var items = [];
|
|
112
|
-
this.values.forEach(function (item) {
|
|
113
|
-
var list = _this.fields.map(function (k) { return item[k] || ''; });
|
|
114
|
-
items.push(utils_1.MysqlParser.toValuesOf(list));
|
|
115
|
-
});
|
|
116
|
-
return items.join(',\n');
|
|
117
|
-
},
|
|
118
|
-
enumerable: false,
|
|
119
|
-
configurable: true
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(MysqlInserter.prototype, "sql", {
|
|
122
|
-
get: function () {
|
|
123
|
-
var target = 'INSERT INTO $tableName';
|
|
124
|
-
target += this._fieldSql;
|
|
125
|
-
if (!this._valueSql) {
|
|
126
|
-
return "".concat(target, "\nVALUES\n").concat(this._valueSql, ";");
|
|
127
|
-
}
|
|
128
|
-
return '';
|
|
129
|
-
},
|
|
130
|
-
enumerable: false,
|
|
131
|
-
configurable: true
|
|
132
|
-
});
|
|
133
|
-
MysqlInserter.prototype.push = function () {
|
|
134
|
-
var _a;
|
|
135
|
-
var _this = this;
|
|
136
|
-
var list = [];
|
|
137
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
138
|
-
list[_i] = arguments[_i];
|
|
139
|
-
}
|
|
140
|
-
if (list.length > 0) {
|
|
141
|
-
Object.keys(list[0]).forEach(function (k) {
|
|
142
|
-
if (!_this.fields.includes(k)) {
|
|
143
|
-
_this.fields.push(k);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
(_a = this.values).push.apply(_a, list);
|
|
148
|
-
};
|
|
149
|
-
// 插入数据
|
|
150
|
-
MysqlInserter.prototype.result = function () {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
return __generator(this, function (_a) {
|
|
153
|
-
return [2 /*return*/];
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
return MysqlInserter;
|
|
158
|
-
}());
|
|
159
|
-
exports.MysqlInserter = MysqlInserter;
|
|
160
|
-
/** @description 更新数据 */
|
|
161
|
-
var MysqlUpdater = /** @class */ (function () {
|
|
162
|
-
function MysqlUpdater(_tableName) {
|
|
163
|
-
this._tableName = _tableName;
|
|
164
|
-
}
|
|
165
|
-
return MysqlUpdater;
|
|
166
|
-
}());
|
|
167
|
-
exports.MysqlUpdater = MysqlUpdater;
|
|
168
|
-
/** @description 删除数据 */
|
|
169
|
-
var MysqlDeleter = /** @class */ (function () {
|
|
170
|
-
function MysqlDeleter(_tableName) {
|
|
171
|
-
this._tableName = _tableName;
|
|
172
|
-
}
|
|
173
|
-
return MysqlDeleter;
|
|
174
|
-
}());
|
|
175
|
-
exports.MysqlDeleter = MysqlDeleter;
|
package/types/selector.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { SortKey, Condition, ConditionProps, Options } from './meta';
|
|
2
|
-
/** @description 查询数据 */
|
|
3
|
-
export declare class MysqlSelector {
|
|
4
|
-
_tableName: string;
|
|
5
|
-
constructor(_tableName: string);
|
|
6
|
-
conditions: Condition[];
|
|
7
|
-
options: Options;
|
|
8
|
-
get sql(): string;
|
|
9
|
-
select(opts: ConditionProps): this;
|
|
10
|
-
limit(n: number): this;
|
|
11
|
-
skip(n: number): this;
|
|
12
|
-
sort(field: string, v: SortKey): this;
|
|
13
|
-
/** @查询结果 */
|
|
14
|
-
result(): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
/** @description 插入数据 */
|
|
17
|
-
export declare class MysqlInserter {
|
|
18
|
-
_tableName: string;
|
|
19
|
-
constructor(_tableName: string);
|
|
20
|
-
fields: string[];
|
|
21
|
-
values: Array<Record<string, unknown>>;
|
|
22
|
-
get _fieldSql(): string;
|
|
23
|
-
get _valueSql(): string;
|
|
24
|
-
get sql(): string;
|
|
25
|
-
push(...list: Record<string, unknown>[]): void;
|
|
26
|
-
result(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
/** @description 更新数据 */
|
|
29
|
-
export declare class MysqlUpdater {
|
|
30
|
-
_tableName: string;
|
|
31
|
-
constructor(_tableName: string);
|
|
32
|
-
}
|
|
33
|
-
/** @description 删除数据 */
|
|
34
|
-
export declare class MysqlDeleter {
|
|
35
|
-
_tableName: string;
|
|
36
|
-
constructor(_tableName: string);
|
|
37
|
-
}
|