@itrocks/mysql-to-schema 0.0.5 → 0.0.7
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 +2 -2
- package/cjs/to-index.js +1 -1
- package/cjs/to-type.js +5 -4
- package/esm/to-column.js +2 -2
- package/esm/to-index.js +1 -1
- package/esm/to-type.js +5 -4
- package/package.json +1 -1
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
|
@@ -45,7 +45,7 @@ class ToIndex {
|
|
|
45
45
|
keys.push(this.rowToKey(row));
|
|
46
46
|
}
|
|
47
47
|
const row = rows[0];
|
|
48
|
-
return new schema_1.Index(row.INDEX_NAME, keys, { type: row.
|
|
48
|
+
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
49
|
}
|
|
50
50
|
rowToKey(row) {
|
|
51
51
|
return new schema_2.IndexKey(row.COLUMN_NAME, row.SUB_PART ?? undefined);
|
package/cjs/to-type.js
CHANGED
|
@@ -139,7 +139,7 @@ class ToType {
|
|
|
139
139
|
case 'mediumint': return signed ? 8388607 : 16777215;
|
|
140
140
|
case 'int':
|
|
141
141
|
case 'integer': return signed ? 2147483647 : 4294967295;
|
|
142
|
-
case 'bigint': return signed ? 2n ** 63n - 1n : 2n ** 64n - 1n;
|
|
142
|
+
case 'bigint': return signed ? (2n ** 63n - 1n) : (2n ** 64n - 1n);
|
|
143
143
|
}
|
|
144
144
|
return undefined;
|
|
145
145
|
}
|
|
@@ -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
|
-
|
|
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
|
@@ -42,7 +42,7 @@ export class ToIndex {
|
|
|
42
42
|
keys.push(this.rowToKey(row));
|
|
43
43
|
}
|
|
44
44
|
const row = rows[0];
|
|
45
|
-
return new Index(row.INDEX_NAME, keys, { type: row.
|
|
45
|
+
return new Index(row.INDEX_NAME, keys, { type: row.NON_UNIQUE ? 'key' : ((row.INDEX_NAME === 'PRIMARY') ? 'primary' : 'unique'), unique: !row.NON_UNIQUE });
|
|
46
46
|
}
|
|
47
47
|
rowToKey(row) {
|
|
48
48
|
return new IndexKey(row.COLUMN_NAME, row.SUB_PART ?? undefined);
|
package/esm/to-type.js
CHANGED
|
@@ -136,7 +136,7 @@ export class ToType {
|
|
|
136
136
|
case 'mediumint': return signed ? 8388607 : 16777215;
|
|
137
137
|
case 'int':
|
|
138
138
|
case 'integer': return signed ? 2147483647 : 4294967295;
|
|
139
|
-
case 'bigint': return signed ? 2n ** 63n - 1n : 2n ** 64n - 1n;
|
|
139
|
+
case 'bigint': return signed ? (2n ** 63n - 1n) : (2n ** 64n - 1n);
|
|
140
140
|
}
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
@@ -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
|
-
|
|
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