Skip to content

Commit f78d7dc

Browse files
committed
fix(note): escape single quote from documentation, closes #13
1 parent aab7bb2 commit f78d7dc

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

__tests__/dbml.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Table User {
5353
id Int [pk, increment]
5454
name String [not null]
5555
profile Profile
56-
role Role [not null, default: 'USER', note: 'User Role']
56+
role Role [not null, default: 'USER', note: 'User\\'s Role']
5757
}
5858
5959
Table Profile {
@@ -62,7 +62,7 @@ Table Profile {
6262
user User [not null]
6363
userId Int [not null]
6464
65-
Note: 'User Profile model'
65+
Note: 'User\\'s Profile model'
6666
}
6767
6868
Enum Role {

__tests__/fixtures/dbml.datamodel.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export const datamodelDbmlComments = /* Prisma */ `
6565
id Int @id @default(autoincrement())
6666
name String
6767
profile Profile?
68-
role Role @default(USER) /// User Role
68+
role Role @default(USER) /// User's Role
6969
}
70-
/// User Profile model
70+
/// User's Profile model
7171
model Profile {
7272
id Int @id @default(autoincrement())
7373
name String

prisma/dbml/schema.dbml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Table User {
1010
name String
1111
posts Post [not null]
1212
profile Profile
13-
role Role [not null, default: 'USER', note: 'user role']
13+
role Role [not null, default: 'USER', note: 'user\'s role']
1414
}
1515

1616
Table Profile {

prisma/schema.prisma

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ model User {
2222
name String?
2323
posts Post[]
2424
profile Profile?
25-
/// user role
25+
/// user's role
2626
role Role @default(USER)
2727
}
2828

src/generator/table.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const generateTableCompositeUniqueIndex = (
4242
};
4343

4444
const generateTableDocumentation = (model: DMMF.Model): string => {
45-
const doc = model.documentation;
45+
const doc = model.documentation?.replace("'", "\\'");
4646
return doc ? `\n\n Note: '${doc}'` : '';
4747
};
4848

@@ -86,7 +86,9 @@ const generateColumnDefinition = (field: DMMF.Field): string => {
8686
}
8787

8888
if (field.documentation) {
89-
columnDefinition.push(`${DBMLKeywords.Note}: '${field.documentation}'`);
89+
columnDefinition.push(
90+
`${DBMLKeywords.Note}: '${field.documentation.replace("'", "\\'")}'`
91+
);
9092
}
9193

9294
if (columnDefinition.length) {

0 commit comments

Comments
 (0)