Skip to content

Commit

Permalink
fix(core): add TS non-null assertion operator for non-nullable columns (
Browse files Browse the repository at this point in the history
  • Loading branch information
soroushjp committed Feb 12, 2020
1 parent 283e58d commit e6d6f21
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 84 deletions.
8 changes: 5 additions & 3 deletions lib/schema/EntityGenerator.ts
Expand Up @@ -70,10 +70,12 @@ export class EntityGenerator {
}

private getPropertyDefinition(column: Column, prop: string, type: string, defaultValue: any): string {
const ret = `${prop}${column.nullable ? '?' : ''}: ${type}`;

// string defaults are usually things like SQL functions
if (!defaultValue || typeof defaultValue === 'string') {
const useDefault = defaultValue && typeof defaultValue !== 'string';
const optional = column.nullable ? '?' : (useDefault ? '' : '!');
const ret = `${prop}${optional}: ${type}`;

if (!useDefault) {
return ret + ';';
}

Expand Down

0 comments on commit e6d6f21

Please sign in to comment.