Skip to content

Commit

Permalink
fix: escape default values properly in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
r1tsuu committed Dec 16, 2024
1 parent a7b9cf4 commit dba8c96
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/db-sqlite/src/columnToCodeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const columnToCodeConverter: ColumnToCodeConverter = ({
if (column.type === 'jsonb' || column.type === 'geometry') {
sanitizedDefault = `'${JSON.stringify(column.default)}'`
} else if (typeof column.default === 'string' || column.type === 'numeric') {
sanitizedDefault = `'${column.default}'`
sanitizedDefault = JSON.stringify(column.default)
}

code = `${code}.default(${sanitizedDefault})`
Expand Down
4 changes: 2 additions & 2 deletions packages/drizzle/src/postgres/columnToCodeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export const columnToCodeConverter: ColumnToCodeConverter = ({
} else if (column.type === 'jsonb') {
sanitizedDefault = `sql\`'${JSON.stringify(column.default)}'::jsonb\``
} else if (column.type === 'numeric') {
sanitizedDefault = `sql\`${column.default}\``
} else if (typeof column.default === 'string') {
sanitizedDefault = `'${column.default}'`
} else if (typeof column.default === 'string') {
sanitizedDefault = `${JSON.stringify(column.default)}`
}

code = `${code}.default(${sanitizedDefault})`
Expand Down

0 comments on commit dba8c96

Please sign in to comment.