Nullable columns now also add "| null" to the type declaration.
Unknown DB types now generate properties with type "NonNullable<unknown>" that also adds "| null" if the column is nullable.
This commit is contained in:
parent
c2d1e038a5
commit
3bbabd127b
@ -376,11 +376,19 @@ export default abstract class AbstractDriver {
|
||||
ownerColumns[0].tscName,
|
||||
ownerEntity
|
||||
);
|
||||
let relationIdType = ownerColumns[0].tscType;
|
||||
if (ownerColumns[0].options.nullable) {
|
||||
relationIdType += " | null";
|
||||
}
|
||||
ownerEntity.relationIds.push({
|
||||
fieldName: relationIdFieldName,
|
||||
fieldType: isOneToMany
|
||||
? `${ownerColumns[0].tscType}[]`
|
||||
: ownerColumns[0].tscType,
|
||||
? `${
|
||||
relationIdType.includes(" ")
|
||||
? `(${relationIdType})`
|
||||
: relationIdType
|
||||
}[]`
|
||||
: relationIdType,
|
||||
relationField: ownerRelation.fieldName
|
||||
});
|
||||
// TODO: RelationId on ManyToMany
|
||||
|
@ -90,7 +90,7 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
|
||||
resp.COLUMN_DEFAULT
|
||||
);
|
||||
const columnType = resp.DATA_TYPE;
|
||||
let tscType = "";
|
||||
let tscType = "NonNullable<unknown>";
|
||||
switch (resp.DATA_TYPE) {
|
||||
case "bigint":
|
||||
tscType = "string";
|
||||
|
@ -69,7 +69,7 @@ export default class MysqlDriver extends AbstractDriver {
|
||||
.filter(filterVal => filterVal.TABLE_NAME === ent.tscName)
|
||||
.forEach(resp => {
|
||||
const tscName = resp.COLUMN_NAME;
|
||||
let tscType = "";
|
||||
let tscType = "NonNullable<unknown>";
|
||||
const options: Column["options"] = {
|
||||
name: resp.COLUMN_NAME
|
||||
};
|
||||
|
@ -87,7 +87,7 @@ export default class OracleDriver extends AbstractDriver {
|
||||
);
|
||||
const DATA_TYPE = resp.DATA_TYPE.replace(/\([0-9]+\)/g, "");
|
||||
const columnType = DATA_TYPE.toLowerCase();
|
||||
let tscType = "";
|
||||
let tscType = "NonNullable<unknown>";
|
||||
switch (DATA_TYPE.toLowerCase()) {
|
||||
case "char":
|
||||
tscType = "string";
|
||||
|
@ -99,7 +99,7 @@ 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"
|
||||
@ -152,16 +152,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;
|
||||
@ -173,17 +172,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: "NonNullable<unknown>",
|
||||
sqlType: dataType,
|
||||
isArray: false,
|
||||
enumValues: []
|
||||
};
|
||||
ret.sqlType = dataType;
|
||||
switch (dataType) {
|
||||
case "int2":
|
||||
ret.tsType = "number";
|
||||
@ -389,17 +387,10 @@ 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;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ export default class SqliteDriver extends AbstractDriver {
|
||||
}>(`PRAGMA table_info('${ent.tscName}');`);
|
||||
response.forEach(resp => {
|
||||
const tscName = resp.name;
|
||||
let tscType = "";
|
||||
let tscType = "NonNullable<unknown>";
|
||||
const options: Column["options"] = { name: resp.name };
|
||||
if (resp.notnull === 0) options.nullable = true;
|
||||
const isPrimary = resp.pk > 0 ? true : undefined;
|
||||
|
@ -6,7 +6,7 @@ import { {{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"}}
|
||||
|
Loading…
Reference in New Issue
Block a user