(decl: AbstractDeclaration | DataField | EnumField, includeSchema: boolean = false)
| 94 | } |
| 95 | |
| 96 | export function getDbName(decl: AbstractDeclaration | DataField | EnumField, includeSchema: boolean = false): string { |
| 97 | if (!('attributes' in decl)) return decl.name; |
| 98 | |
| 99 | const schemaAttr = decl.attributes.find((a) => a.decl.ref?.name === '@@schema'); |
| 100 | let schema = 'public'; |
| 101 | if (schemaAttr) { |
| 102 | const schemaAttrValue = schemaAttr.args[0]?.value; |
| 103 | if (schemaAttrValue?.$type === 'StringLiteral') { |
| 104 | schema = schemaAttrValue.value; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | const formatName = (name: string) => `${schema && includeSchema ? `${schema}.` : ''}${name}`; |
| 109 | |
| 110 | const nameAttr = decl.attributes.find((a) => a.decl.ref?.name === '@@map' || a.decl.ref?.name === '@map'); |
| 111 | if (!nameAttr) return formatName(decl.name); |
| 112 | const attrValue = nameAttr.args[0]?.value; |
| 113 | |
| 114 | if (attrValue?.$type !== 'StringLiteral') return formatName(decl.name); |
| 115 | |
| 116 | return formatName(attrValue.value); |
| 117 | } |
| 118 | |
| 119 | export function getRelationFkName(decl: DataField): string | undefined { |
| 120 | const relationAttr = decl?.attributes.find((a) => a.decl.ref?.name === '@relation'); |
no test coverage detected