commit
48a2dfcbae
@ -369,11 +369,20 @@ export default abstract class AbstractDriver {
|
||||
ownerColumns[0].tscName,
|
||||
ownerEntity
|
||||
);
|
||||
|
||||
let fieldType = "";
|
||||
if (isOneToMany) {
|
||||
fieldType = `${ownerColumns[0].tscType}[]`;
|
||||
} else {
|
||||
fieldType = ownerColumns[0].tscType;
|
||||
if (ownerColumns[0].options.nullable) {
|
||||
fieldType += " | null";
|
||||
}
|
||||
}
|
||||
|
||||
ownerEntity.relationIds.push({
|
||||
fieldName: relationIdFieldName,
|
||||
fieldType: isOneToMany
|
||||
? `${ownerColumns[0].tscType}[]`
|
||||
: ownerColumns[0].tscType,
|
||||
fieldType,
|
||||
relationField: ownerRelation.fieldName
|
||||
});
|
||||
// TODO: RelationId on ManyToMany
|
||||
|
@ -204,6 +204,7 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
|
||||
tscType = "string";
|
||||
break;
|
||||
default:
|
||||
tscType = "NonNullable<unknown>";
|
||||
TomgUtils.LogError(
|
||||
`Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}`
|
||||
);
|
||||
@ -230,17 +231,14 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
|
||||
? resp.CHARACTER_MAXIMUM_LENGTH
|
||||
: undefined;
|
||||
}
|
||||
|
||||
if (columnType) {
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
}
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
});
|
||||
});
|
||||
return entities;
|
||||
|
@ -237,6 +237,7 @@ export default class MysqlDriver extends AbstractDriver {
|
||||
tscType = "string";
|
||||
break;
|
||||
default:
|
||||
tscType = "NonNullable<unknown>";
|
||||
TomgUtils.LogError(
|
||||
`Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}`
|
||||
);
|
||||
@ -273,16 +274,14 @@ export default class MysqlDriver extends AbstractDriver {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
if (columnType) {
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
}
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
});
|
||||
});
|
||||
return entities;
|
||||
|
@ -187,6 +187,7 @@ export default class OracleDriver extends AbstractDriver {
|
||||
tscType = "number";
|
||||
break;
|
||||
default:
|
||||
tscType = "NonNullable<unknown>";
|
||||
TomgUtils.LogError(
|
||||
`Unknown column type:${DATA_TYPE}`
|
||||
);
|
||||
@ -211,16 +212,14 @@ export default class OracleDriver extends AbstractDriver {
|
||||
resp.DATA_LENGTH > 0 ? resp.DATA_LENGTH : undefined;
|
||||
}
|
||||
|
||||
if (columnType) {
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
}
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
});
|
||||
});
|
||||
return entities;
|
||||
|
@ -111,21 +111,22 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
resp.udt_name,
|
||||
resp.enumvalues
|
||||
);
|
||||
if (!columnTypes.sqlType || !columnTypes.tsType) {
|
||||
if (columnTypes.tsType === "NonNullable<unknown>") {
|
||||
if (
|
||||
resp.data_type === "USER-DEFINED" ||
|
||||
resp.data_type === "ARRAY"
|
||||
) {
|
||||
TomgUtils.LogError(
|
||||
`Unknown ${resp.data_type} column type: ${resp.udt_name} table name: ${resp.table_name} column name: ${resp.column_name}`
|
||||
`Unknown ${resp.data_type} column type: ${resp.udt_name} table name: ${resp.table_name} column name: ${resp.column_name}`
|
||||
);
|
||||
} else {
|
||||
TomgUtils.LogError(
|
||||
`Unknown column type: ${resp.data_type} table name: ${resp.table_name} column name: ${resp.column_name}`
|
||||
`Unknown column type: ${resp.data_type} table name: ${resp.table_name} column name: ${resp.column_name}`
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const columnType = columnTypes.sqlType;
|
||||
let tscType = columnTypes.tsType;
|
||||
if (columnTypes.isArray) options.array = true;
|
||||
@ -164,16 +165,15 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
? resp.character_maximum_length
|
||||
: undefined;
|
||||
}
|
||||
if (columnType && tscType) {
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
}
|
||||
|
||||
ent.columns.push({
|
||||
generated,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
});
|
||||
});
|
||||
return entities;
|
||||
@ -185,17 +185,16 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
enumValues: string | null
|
||||
) {
|
||||
let ret: {
|
||||
tsType?: Column["tscType"];
|
||||
sqlType: string | null;
|
||||
tsType: Column["tscType"];
|
||||
sqlType: string;
|
||||
isArray: boolean;
|
||||
enumValues: string[];
|
||||
} = {
|
||||
tsType: undefined,
|
||||
sqlType: null,
|
||||
tsType: "",
|
||||
sqlType: dataType,
|
||||
isArray: false,
|
||||
enumValues: []
|
||||
};
|
||||
ret.sqlType = dataType;
|
||||
switch (dataType) {
|
||||
case "int2":
|
||||
ret.tsType = "number";
|
||||
@ -401,16 +400,12 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
.join('" | "')}"` as never) as string;
|
||||
ret.sqlType = "enum";
|
||||
ret.enumValues = enumValues.split(",");
|
||||
} else {
|
||||
ret.tsType = undefined;
|
||||
ret.sqlType = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret.tsType = undefined;
|
||||
ret.sqlType = null;
|
||||
ret.tsType = "NonNullable<unknown>";
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
@ -172,6 +172,7 @@ export default class SqliteDriver extends AbstractDriver {
|
||||
tscType = "Date";
|
||||
break;
|
||||
default:
|
||||
tscType = "NonNullable<unknown>";
|
||||
TomgUtils.LogError(
|
||||
`Unknown column type: ${columnType} table name: ${ent.tscName} column name: ${resp.name}`
|
||||
);
|
||||
@ -226,17 +227,15 @@ export default class SqliteDriver extends AbstractDriver {
|
||||
);
|
||||
}
|
||||
|
||||
if (columnType) {
|
||||
ent.columns.push({
|
||||
generated,
|
||||
primary: isPrimary,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
}
|
||||
ent.columns.push({
|
||||
generated,
|
||||
primary: isPrimary,
|
||||
type: columnType,
|
||||
default: defaultValue,
|
||||
options,
|
||||
tscName,
|
||||
tscType
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
@ -6,7 +6,7 @@ import {{localImport (toEntityName .)}} from './{{toFileName .}}'
|
||||
{{/inline}}
|
||||
{{#*inline "Column"}}
|
||||
{{#generated}}@PrimaryGeneratedColumn({ type:"{{type}}", {{/generated}}{{^generated}}@Column("{{type}}",{ {{#primary}}primary:{{primary}},{{/primary}}{{/generated}}{{json options}}{{#default}},default: {{.}},{{/default}} })
|
||||
{{printPropertyVisibility}}{{toPropertyName tscName}}{{strictMode}}:{{tscType}};
|
||||
{{printPropertyVisibility}}{{toPropertyName tscName}}{{strictMode}}:{{tscType}}{{#if options.nullable}} | null{{/if}};
|
||||
|
||||
{{/inline}}
|
||||
{{#*inline "JoinColumnOptions"}}
|
||||
|
@ -74,7 +74,7 @@ describe("MssqlDriver", () => {
|
||||
COLUMN_DEFAULT: "'a'",
|
||||
COLUMN_NAME: "name",
|
||||
DATA_TYPE: "int",
|
||||
IS_NULLABLE: "YES",
|
||||
IS_NULLABLE: "NO",
|
||||
NUMERIC_PRECISION: 0,
|
||||
NUMERIC_SCALE: 0,
|
||||
IsIdentity: 1
|
||||
@ -99,7 +99,6 @@ describe("MssqlDriver", () => {
|
||||
const expected: Entity[] = JSON.parse(JSON.stringify(entities));
|
||||
expected[0].columns.push({
|
||||
options: {
|
||||
nullable: true,
|
||||
name: "name"
|
||||
},
|
||||
type: "int",
|
||||
|
15
test/integration/github-issues/227/entity/Post.ts
Normal file
15
test/integration/github-issues/227/entity/Post.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } from "typeorm";
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column("varchar", { nullable: true })
|
||||
title: string | null;
|
||||
|
||||
@Column()
|
||||
text: string;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user