tspace-mysql 1.3.3 → 1.3.5

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.
@@ -1,8 +1,13 @@
1
1
  import { Builder } from "./Builder";
2
2
  declare class Schema extends Builder {
3
- table: (table: string, schemas: {
4
- [x: string]: any;
5
- }) => Promise<void>;
3
+ table: (table: string, schemas: Record<string, {
4
+ type: string;
5
+ attrbuites: string[];
6
+ }>) => Promise<void>;
7
+ createTable: (table: string, schemas: Record<string, {
8
+ type: string;
9
+ attrbuites: string[];
10
+ }>) => Promise<any>;
6
11
  }
7
12
  export { Schema };
8
13
  export default Schema;
@@ -39,6 +39,23 @@ class Schema extends Builder_1.Builder {
39
39
  console.log((_a = err.message) === null || _a === void 0 ? void 0 : _a.replace(/ER_TABLE_EXISTS_ERROR:/g, ""));
40
40
  }
41
41
  });
42
+ this.createTable = (table, schemas) => __awaiter(this, void 0, void 0, function* () {
43
+ let columns = [];
44
+ for (const key in schemas) {
45
+ const data = schemas[key];
46
+ const { type, attrbuites } = data;
47
+ columns = [
48
+ ...columns,
49
+ `${key} ${type} ${attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' ')}`
50
+ ];
51
+ }
52
+ const sql = [
53
+ `CREATE TABLE IF NOT EXISTS`,
54
+ `${table} (${columns === null || columns === void 0 ? void 0 : columns.join(', ')})`,
55
+ `ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8`
56
+ ].join(' ');
57
+ return yield this.rawQuery(sql);
58
+ });
42
59
  }
43
60
  }
44
61
  exports.Schema = Schema;
@@ -0,0 +1,12 @@
1
+ declare class StateHandler {
2
+ private STATE;
3
+ constructor(constant: Record<string, any>);
4
+ original(): Map<string, any>;
5
+ get(key?: string | null): any;
6
+ set(key: string, value: any): void;
7
+ clone(data: any): void;
8
+ resetState(): void;
9
+ private _assertError;
10
+ }
11
+ export { StateHandler };
12
+ export default StateHandler;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StateHandler = void 0;
4
+ class StateHandler {
5
+ constructor(constant) {
6
+ this.STATE = {
7
+ currentState: new Map(),
8
+ defaultState: new Map()
9
+ };
10
+ const currentState = new Map(Object.entries(Object.assign({}, constant)));
11
+ const defaultState = new Map(Object.entries(Object.assign({}, constant)));
12
+ this.STATE = {
13
+ currentState,
14
+ defaultState
15
+ };
16
+ }
17
+ original() {
18
+ return this.STATE.defaultState;
19
+ }
20
+ get(key) {
21
+ if (key == null)
22
+ return this.STATE.currentState;
23
+ this._assertError(!this.STATE.currentState.has(key) && key !== 'DEBUG', `Can't get this [ ${key} ]`);
24
+ return this.STATE.currentState.get(key);
25
+ }
26
+ set(key, value) {
27
+ this._assertError(!this.STATE.currentState.has(key), `Can't set this [ ${key} ]`);
28
+ this.STATE.currentState.set(key, value);
29
+ return;
30
+ }
31
+ clone(data) {
32
+ this.STATE.currentState = new Map(Object.entries(Object.assign({}, data)));
33
+ return;
34
+ }
35
+ resetState() {
36
+ this.STATE.currentState.set('INSERT', '');
37
+ this.STATE.currentState.set('UPDATE', '');
38
+ this.STATE.currentState.set('DELETE', '');
39
+ this.STATE.currentState.set('WHERE', '');
40
+ this.STATE.currentState.set('LIMIT', '');
41
+ this.STATE.currentState.set('OFFSET', '');
42
+ this.STATE.currentState.set('SAVE', '');
43
+ return;
44
+ }
45
+ _assertError(condition = true, message = 'error') {
46
+ if (typeof condition === 'string') {
47
+ throw new Error(condition);
48
+ }
49
+ if (condition)
50
+ throw new Error(message);
51
+ return;
52
+ }
53
+ }
54
+ exports.StateHandler = StateHandler;
55
+ exports.default = StateHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tspace-mysql",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "mysql query builder object relational mapping",
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "mysql",
21
21
  "orm",
22
22
  "relations",
23
+ "deeply nested relations",
23
24
  "object relation model",
24
25
  "model",
25
26
  "database",