Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/builders/ModelBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ export class ModelBuilder extends Builder {
undefined,
undefined,
[
...(Object.values(columns).map(c => ts.factory.createPropertySignature(
undefined,
ts.factory.createIdentifier(c.name),
c.autoIncrement || c.allowNull || c.defaultValue !== undefined ?
...(Object.values(columns).map(c => {
const property = ts.factory.createPropertySignature(
undefined,
ts.factory.createIdentifier(c.name),
c.autoIncrement || c.allowNull || c.defaultValue !== undefined ?
ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,
ts.factory.createTypeReferenceNode(dialect.mapDbTypeToJs(c.type) ?? 'any', undefined)
)))
ts.factory.createTypeReferenceNode(dialect.mapDbTypeToJs(c.type) ?? 'any', undefined)
)
return c.comment ? ts.addSyntheticLeadingComment(property, ts.SyntaxKind.MultiLineCommentTrivia, `* ${c.comment}`, true) : property
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change here to add the comments using addSyntheticLeadingComment

})
)
]
);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/integration/mariadb/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AUTHORS_TABLE_CREATES = [
`
CREATE TABLE ${AUTHORS_TABLE_NAME}
(
author_id INT primary key,
author_id INT primary key COMMENT 'This column stores the PK',
full_name VARCHAR(80) not null
);
`,
Expand Down
6 changes: 6 additions & 0 deletions src/tests/integration/mssql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export const AUTHORS_TABLE_CREATES = [
full_name VARCHAR(80) not null
);
`,
`EXEC sp_addextendedproperty
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated all the tests to add their version of a comment and they all pass when I run them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception is sqllite as it doesn't support comments

@name = N'MS_Description',
@value = 'This column stores the PK',
@level0type = N'SCHEMA', @level0name = 'dbo',
@level1type = N'TABLE', @level1name = 'authors',
@level2type = N'COLUMN', @level2name = 'author_id';`
];
export const AUTHORS_TABLE_INSERTS = [
`INSERT INTO ${AUTHORS_TABLE_NAME} VALUES (1, 'Isasc Asimov');`,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/integration/mysql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AUTHORS_TABLE_CREATES = [
`
CREATE TABLE ${AUTHORS_TABLE_NAME}
(
author_id INT primary key,
author_id INT primary key COMMENT 'This column stores the PK',
full_name VARCHAR(80) not null
);
`,
Expand Down
1 change: 1 addition & 0 deletions src/tests/integration/postgres/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const AUTHORS_TABLE_CREATES = [
full_name VARCHAR(80) not null
);
`,
`COMMENT ON COLUMN public.authors.author_id IS 'This column stores the PK';`
];
export const AUTHORS_TABLE_INSERTS = [
`INSERT INTO ${SCHEMA_NAME}.${AUTHORS_TABLE_NAME} VALUES (1, 'Isasc Asimov');`,
Expand Down