@itrocks/mysql-to-schema 0.0.6 → 0.0.8

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/cjs/to-column.js CHANGED
@@ -41,8 +41,8 @@ class ToColumn {
41
41
  canBeNull: row.IS_NULLABLE === 'YES',
42
42
  default: row.COLUMN_DEFAULT
43
43
  });
44
- if ((column.default === null) && !column.canBeNull) {
45
- column.default = undefined;
44
+ if (((column.default === null) || (column.default === undefined)) && !column.canBeNull) {
45
+ column.default = (type.name === 'string') ? '' : undefined;
46
46
  }
47
47
  return column;
48
48
  }
package/cjs/to-index.js CHANGED
@@ -22,7 +22,6 @@ class ToIndex {
22
22
  + ' FROM information_schema.STATISTICS'
23
23
  + ` WHERE TABLE_SCHEMA = ${databaseName} AND TABLE_NAME = '${tableName}'`
24
24
  + ' ORDER BY INDEX_NAME, SEQ_IN_INDEX';
25
- console.log(query);
26
25
  const indexes = [];
27
26
  let lastRow = undefined;
28
27
  const rows = [];
@@ -45,7 +44,7 @@ class ToIndex {
45
44
  keys.push(this.rowToKey(row));
46
45
  }
47
46
  const row = rows[0];
48
- return new schema_1.Index(row.INDEX_NAME, keys, { type: row.INDEX_TYPE, unique: !row.NON_UNIQUE });
47
+ return new schema_1.Index(row.INDEX_NAME, keys, { type: row.NON_UNIQUE ? 'key' : ((row.INDEX_NAME === 'PRIMARY') ? 'primary' : 'unique'), unique: !row.NON_UNIQUE });
49
48
  }
50
49
  rowToKey(row) {
51
50
  return new schema_2.IndexKey(row.COLUMN_NAME, row.SUB_PART ?? undefined);
package/cjs/to-type.js CHANGED
@@ -174,9 +174,10 @@ class ToType {
174
174
  type.length = 53;
175
175
  break;
176
176
  case 'integer':
177
- if (type.length === undefined)
178
- type.length = 20;
179
- else if (type.length > 10)
177
+ if (type.length === undefined) {
178
+ type.length = (type.maxValue === undefined) ? 20 : type.maxValue.toString().length;
179
+ }
180
+ if (type.length > 10)
180
181
  type.length = 20;
181
182
  else if (type.length > 8)
182
183
  type.length = 10;
package/esm/to-column.js CHANGED
@@ -38,8 +38,8 @@ export class ToColumn {
38
38
  canBeNull: row.IS_NULLABLE === 'YES',
39
39
  default: row.COLUMN_DEFAULT
40
40
  });
41
- if ((column.default === null) && !column.canBeNull) {
42
- column.default = undefined;
41
+ if (((column.default === null) || (column.default === undefined)) && !column.canBeNull) {
42
+ column.default = (type.name === 'string') ? '' : undefined;
43
43
  }
44
44
  return column;
45
45
  }
package/esm/to-index.js CHANGED
@@ -19,7 +19,6 @@ export class ToIndex {
19
19
  + ' FROM information_schema.STATISTICS'
20
20
  + ` WHERE TABLE_SCHEMA = ${databaseName} AND TABLE_NAME = '${tableName}'`
21
21
  + ' ORDER BY INDEX_NAME, SEQ_IN_INDEX';
22
- console.log(query);
23
22
  const indexes = [];
24
23
  let lastRow = undefined;
25
24
  const rows = [];
@@ -42,7 +41,7 @@ export class ToIndex {
42
41
  keys.push(this.rowToKey(row));
43
42
  }
44
43
  const row = rows[0];
45
- return new Index(row.INDEX_NAME, keys, { type: row.INDEX_TYPE, unique: !row.NON_UNIQUE });
44
+ return new Index(row.INDEX_NAME, keys, { type: row.NON_UNIQUE ? 'key' : ((row.INDEX_NAME === 'PRIMARY') ? 'primary' : 'unique'), unique: !row.NON_UNIQUE });
46
45
  }
47
46
  rowToKey(row) {
48
47
  return new IndexKey(row.COLUMN_NAME, row.SUB_PART ?? undefined);
package/esm/to-type.js CHANGED
@@ -171,9 +171,10 @@ export class ToType {
171
171
  type.length = 53;
172
172
  break;
173
173
  case 'integer':
174
- if (type.length === undefined)
175
- type.length = 20;
176
- else if (type.length > 10)
174
+ if (type.length === undefined) {
175
+ type.length = (type.maxValue === undefined) ? 20 : type.maxValue.toString().length;
176
+ }
177
+ if (type.length > 10)
177
178
  type.length = 20;
178
179
  else if (type.length > 8)
179
180
  type.length = 10;
package/package.json CHANGED
@@ -45,5 +45,5 @@
45
45
  "build:esm": "tsc -p tsconfig.esm.json"
46
46
  },
47
47
  "types": "./esm/mysql-to-schema.d.ts",
48
- "version": "0.0.6"
48
+ "version": "0.0.8"
49
49
  }