mirror of
https://github.com/theoludwig/kysely-typegen.git
synced 2026-10-16 19:16:47 +02:00
feat: generate JSDoc from column comments
This commit is contained in:
6 files changed
+74
-3
No files matched your search
@@ -73,6 +73,24 @@ export abstract class KyselyTypegenDialect {
|
||||
return scalars[dataType] ?? "unknown"
|
||||
}
|
||||
|
||||
protected formatColumnComment(comment: string): string[] {
|
||||
const trimmedComment = comment.trim()
|
||||
if (trimmedComment.length === 0) {
|
||||
return []
|
||||
}
|
||||
const lines = trimmedComment.replaceAll("*/", "*\\/").split(/\r?\n/u)
|
||||
if (lines.length === 1) {
|
||||
return [` /** ${lines[0]} */`]
|
||||
}
|
||||
return [
|
||||
" /**",
|
||||
...lines.map((line) => {
|
||||
return line.length === 0 ? " *" : ` * ${line}`
|
||||
}),
|
||||
" */",
|
||||
]
|
||||
}
|
||||
|
||||
public getTablesTypegen(
|
||||
tables: TableMetadata[],
|
||||
enums: EnumMetadata[],
|
||||
@@ -94,6 +112,9 @@ export abstract class KyselyTypegenDialect {
|
||||
if (column.hasDefaultValue || column.isAutoIncrementing) {
|
||||
columnType = `Generated<${columnType}>`
|
||||
}
|
||||
if (column.comment != null) {
|
||||
result.push(...this.formatColumnComment(column.comment))
|
||||
}
|
||||
result.push(` ${column.name}: ${columnType}`)
|
||||
}
|
||||
result.push("}", "")
|
||||
|
||||
Reference in new issue
Block a user