(
field: string | Raw | RawQueryFragmentSymbol,
type = QueryType.SELECT,
value?: any,
alias?: string | null,
schema?: string,
)
| 111 | schema?: string, |
| 112 | ): string; |
| 113 | mapper( |
| 114 | field: string | Raw | RawQueryFragmentSymbol, |
| 115 | type = QueryType.SELECT, |
| 116 | value?: any, |
| 117 | alias?: string | null, |
| 118 | schema?: string, |
| 119 | ): string | Raw { |
| 120 | if (isRaw(field)) { |
| 121 | return raw(field.sql, field.params); |
| 122 | } |
| 123 | |
| 124 | if (Raw.isKnownFragmentSymbol(field)) { |
| 125 | return Raw.getKnownFragment(field)!; |
| 126 | } |
| 127 | |
| 128 | /* v8 ignore next */ |
| 129 | if (typeof field !== 'string') { |
| 130 | return field; |
| 131 | } |
| 132 | |
| 133 | const isTableNameAliasRequired = this.isTableNameAliasRequired(type); |
| 134 | const fields = Utils.splitPrimaryKeys(field); |
| 135 | |
| 136 | if (fields.length > 1) { |
| 137 | const parts: string[] = []; |
| 138 | |
| 139 | for (const p of fields) { |
| 140 | const [a, f] = this.splitField(p); |
| 141 | const prop = this.getProperty(f, a); |
| 142 | const fkIdx2 = prop?.fieldNames.findIndex(name => name === f) ?? -1; |
| 143 | |
| 144 | if (fkIdx2 !== -1) { |
| 145 | parts.push( |
| 146 | this.mapper( |
| 147 | a !== this.#alias ? `${a}.${prop!.fieldNames[fkIdx2]}` : prop!.fieldNames[fkIdx2], |
| 148 | type, |
| 149 | value, |
| 150 | alias, |
| 151 | ), |
| 152 | ); |
| 153 | } else if (prop) { |
| 154 | parts.push(...prop.fieldNames.map(f => this.mapper(a !== this.#alias ? `${a}.${f}` : f, type, value, alias))); |
| 155 | } else { |
| 156 | parts.push(this.mapper(a !== this.#alias ? `${a}.${f}` : f, type, value, alias)); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // flatten the value if we see we are expanding nested composite key |
| 161 | // hackish, but cleaner solution would require quite a lot of refactoring |
| 162 | if (fields.length !== parts.length && Array.isArray(value)) { |
| 163 | value.forEach(row => { |
| 164 | if (Array.isArray(row)) { |
| 165 | const tmp = Utils.flatten(row); |
| 166 | row.length = 0; |
| 167 | row.push(...tmp); |
| 168 | } |
| 169 | }); |
| 170 | } |
no test coverage detected