sequelize-typescript-generator 7.1.0 → 7.2.0

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.
@@ -59,7 +59,7 @@ class ModelBuilder extends Builder_1.Builder {
59
59
  ...col.allowNull && { allowNull: col.allowNull },
60
60
  ...col.dataType && { type: col.dataType },
61
61
  ...col.comment && { comment: col.comment },
62
- ...col.defaultValue !== undefined && { defaultValue: dialect.mapDefaultValueToSequelize(col.defaultValue.toString()) },
62
+ ...col.defaultValue !== undefined && { defaultValue: dialect.mapDefaultValueToSequelize(col.defaultValue) },
63
63
  };
64
64
  return props;
65
65
  };
@@ -80,7 +80,7 @@ class ModelBuilder extends Builder_1.Builder {
80
80
  ...(col.indices && col.indices.length ?
81
81
  col.indices.map(index => (0, utils_1.generateObjectLiteralDecorator)('Index', buildIndexDecoratorProps(index)))
82
82
  : [])
83
- ], undefined, col.name, (col.autoIncrement || col.allowNull || col.defaultValue) ?
83
+ ], undefined, col.name, (col.autoIncrement || col.allowNull || col.defaultValue !== undefined) ?
84
84
  ts.createToken(ts.SyntaxKind.QuestionToken) : ts.createToken(ts.SyntaxKind.ExclamationToken), ts.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(col.type)) !== null && _a !== void 0 ? _a : 'any', undefined), undefined);
85
85
  }
86
86
  /**
@@ -147,7 +147,7 @@ class ModelBuilder extends Builder_1.Builder {
147
147
  const attributesInterface = ts.createInterfaceDeclaration(undefined, undefined, ts.createIdentifier(attributesInterfaceName), undefined, undefined, [
148
148
  ...(Object.values(columns).map(c => {
149
149
  var _a;
150
- return ts.createPropertySignature(undefined, ts.createIdentifier(c.name), c.autoIncrement || c.allowNull || c.defaultValue ?
150
+ return ts.createPropertySignature(undefined, ts.createIdentifier(c.name), c.autoIncrement || c.allowNull || c.defaultValue !== undefined ?
151
151
  ts.createToken(ts.SyntaxKind.QuestionToken) : undefined, ts.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(c.type)) !== null && _a !== void 0 ? _a : 'any', undefined));
152
152
  }))
153
153
  ]);
@@ -43,7 +43,7 @@ const generateNamedImports = (importsSpecifier, moduleSpecifier) => {
43
43
  /* decorators */ undefined,
44
44
  /* modifiers */ undefined, ts.createImportClause(undefined, ts.createNamedImports([
45
45
  ...importsSpecifier
46
- .map(is => ts.createImportSpecifier(undefined, ts.createIdentifier(is)))
46
+ .map(is => ts.createImportSpecifier(false, undefined, ts.createIdentifier(is)))
47
47
  ])), ts.createLiteral(moduleSpecifier));
48
48
  };
49
49
  exports.generateNamedImports = generateNamedImports;
@@ -63,10 +63,23 @@ exports.generateIndexExport = generateIndexExport;
63
63
  * @return {ts.Decorator}
64
64
  */
65
65
  const generateObjectLiteralDecorator = (decoratorIdentifier, props) => {
66
+ const _createPropertyAssignment = (propName, propValue) => {
67
+ let expression;
68
+ if (typeof propValue === 'number') {
69
+ expression = ts.createNumericLiteral(propValue);
70
+ }
71
+ else if (typeof propValue === 'string' && (propValue.startsWith('DataType.') || propValue.startsWith('Sequelize.'))) {
72
+ expression = ts.createIdentifier(propValue);
73
+ }
74
+ else {
75
+ expression = ts.createLiteral(propValue);
76
+ }
77
+ return ts.createPropertyAssignment(propName, expression);
78
+ };
66
79
  return ts.createDecorator(ts.createCall(ts.createIdentifier(decoratorIdentifier), undefined, [
67
80
  ts.createObjectLiteral([
68
81
  ...Object.entries(props)
69
- .map(e => ts.createPropertyAssignment(e[0], typeof e[1] === 'string' && (e[1].startsWith('DataType.') || e[1].startsWith('Sequelize.')) ? ts.createIdentifier(e[1]) : ts.createLiteral(e[1])))
82
+ .map(e => _createPropertyAssignment(e[0], e[1]))
70
83
  ])
71
84
  ]));
72
85
  };
@@ -160,7 +160,7 @@ class DialectPostgres extends Dialect_1.Dialect {
160
160
  FROM pg_attribute a
161
161
  LEFT OUTER JOIN pg_index x
162
162
  ON a.attnum = ANY (x.indkey) AND a.attrelid = x.indrelid
163
- WHERE a.attrelid = '${config.metadata.schema}.${table}'::regclass AND a.attnum > 0
163
+ WHERE a.attrelid = '${config.metadata.schema}.\"${table}\"'::regclass AND a.attnum > 0
164
164
  AND c.ordinal_position = a.attnum AND x.indisprimary IS TRUE
165
165
  ) AS is_primary,
166
166
  c.*,
@@ -219,7 +219,7 @@ class DialectPostgres extends Dialect_1.Dialect {
219
219
  comment: (_a = column.description) !== null && _a !== void 0 ? _a : undefined,
220
220
  };
221
221
  if (column.column_default) {
222
- columnMetadata.defaultValue = `Sequelize.literal("${column.column_default}")`;
222
+ columnMetadata.defaultValue = `Sequelize.literal("${column.column_default.replace(/\"/g, '\\\"')}")`;
223
223
  }
224
224
  // Additional data type information
225
225
  switch (column.udt_name) {
@@ -268,7 +268,7 @@ class DialectPostgres extends Dialect_1.Dialect {
268
268
  ON x.indexrelid = pc.oid
269
269
  INNER JOIN pg_am am
270
270
  ON pc.relam = am.oid
271
- WHERE a.attrelid = '${config.metadata.schema}.${table}'::regclass AND a.attnum > 0
271
+ WHERE a.attrelid = '${config.metadata.schema}.\"${table}\"'::regclass AND a.attnum > 0
272
272
  AND a.attname = '${column}';
273
273
  `;
274
274
  const indices = await connection.query(query, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sequelize-typescript-generator",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "Automatically generates typescript models compatible with sequelize-typescript library (https://www.npmjs.com/package/sequelize-typescript) directly from your source database.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -35,31 +35,31 @@
35
35
  "homepage": "https://github.com/spinlud/sequelize-typescript-generator.git#readme",
36
36
  "devDependencies": {
37
37
  "@types/bluebird": "^3.5.36",
38
- "@types/jest": "^27.0.2",
39
- "@types/node": "^16.11.1",
38
+ "@types/jest": "^27.0.3",
39
+ "@types/node": "^16.11.10",
40
40
  "@types/pluralize": "0.0.29",
41
- "@types/validator": "^13.6.3",
42
- "@types/yargs": "^17.0.4",
41
+ "@types/validator": "^13.7.0",
42
+ "@types/yargs": "^17.0.7",
43
43
  "jest": "^27.3.1",
44
- "mariadb": "^2.5.4",
45
- "mysql2": "^2.3.2",
44
+ "mariadb": "^2.5.5",
45
+ "mysql2": "^2.3.3",
46
46
  "pg": "^8.7.1",
47
47
  "pg-hstore": "^2.3.4",
48
48
  "reflect-metadata": "^0.1.13",
49
49
  "sqlite3": "^4.2.0",
50
- "tedious": "^11.0.8",
50
+ "tedious": "^14.0.0",
51
51
  "ts-jest": "^27.0.7",
52
52
  "ts-node-dev": "^1.1.8",
53
- "typescript": "^4.4.4",
53
+ "typescript": "^4.5.2",
54
54
  "wkx": "^0.5.0"
55
55
  },
56
56
  "dependencies": {
57
- "@types/eslint": "^7.28.1",
58
- "@typescript-eslint/parser": "^5.1.0",
57
+ "@types/eslint": "^8.2.0",
58
+ "@typescript-eslint/parser": "^5.4.0",
59
59
  "change-case": "^4.1.2",
60
- "eslint": "^8.0.1",
60
+ "eslint": "^8.3.0",
61
61
  "pluralize": "^8.0.0",
62
- "sequelize": "^6.7.0",
62
+ "sequelize": "^6.11.0",
63
63
  "sequelize-typescript": "^2.1.1",
64
64
  "yargs": "^17.2.1"
65
65
  },