@itrocks/schema-to-mysql 0.1.1 → 0.1.3
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/README.md +4 -0
- package/cjs/schema-to-mysql.js +6 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,6 +24,10 @@ tables, columns, and indexes.
|
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
+
Date and datetime columns are always rendered `NOT NULL`, even if the input schema marks them nullable.
|
|
28
|
+
Missing or null defaults become `0000-00-00` for dates and `0000-00-00 00:00:00` for datetimes.
|
|
29
|
+
Explicit non-empty defaults are retained.
|
|
30
|
+
|
|
27
31
|
`@itrocks/schema-to-mysql` exposes a single class, `SchemaToMysql`. It converts
|
|
28
32
|
`Table`, `Column`, `Index`, and `Type` definitions from `@itrocks/schema` into
|
|
29
33
|
MySQL `CREATE TABLE` statements.
|
package/cjs/schema-to-mysql.js
CHANGED
|
@@ -3,10 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SchemaToMysql = void 0;
|
|
4
4
|
class SchemaToMysql {
|
|
5
5
|
columnSql(column) {
|
|
6
|
+
const date = ['date', 'datetime'].includes(column.type.name);
|
|
7
|
+
const defaultValue = (date && (column.default == null))
|
|
8
|
+
? ((column.type.name === 'date') ? '0000-00-00' : '0000-00-00 00:00:00')
|
|
9
|
+
: column.default;
|
|
6
10
|
return '`' + column.name + '` '
|
|
7
11
|
+ this.typeSql(column.type)
|
|
8
|
-
+ ((column.canBeNull === false) ? ' NOT NULL' : '')
|
|
9
|
-
+ ((
|
|
12
|
+
+ ((date || (column.canBeNull === false)) ? ' NOT NULL' : '')
|
|
13
|
+
+ ((defaultValue !== undefined) ? (' DEFAULT ' + this.defaultSql(defaultValue)) : '')
|
|
10
14
|
+ (column.autoIncrement ? ' AUTO_INCREMENT' : '')
|
|
11
15
|
+ ((['enum', 'string', 'set'].includes(column.type.name) && column.type.collate)
|
|
12
16
|
? ' COLLATE ' + column.type.collate
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "Converts a table schema into MySQL statements for table creation",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"typescript": "^
|
|
11
|
+
"typescript": "^7.0"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=24"
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsc"
|
|
52
52
|
},
|
|
53
|
-
"version": "0.1.
|
|
53
|
+
"version": "0.1.3"
|
|
54
54
|
}
|