* Maps raw database result to an entity and merges it to this EntityManager.
(
entityName: EntityName<Entity>,
result: EntityDictionary<Entity>,
options: { schema?: string; mapped?: boolean } = {},
)
| 2019 | * Maps raw database result to an entity and merges it to this EntityManager. |
| 2020 | */ |
| 2021 | map<Entity extends object>( |
| 2022 | entityName: EntityName<Entity>, |
| 2023 | result: EntityDictionary<Entity>, |
| 2024 | options: { schema?: string; mapped?: boolean } = {}, |
| 2025 | ): Entity { |
| 2026 | const { mapped, ...rest } = options; |
| 2027 | const meta = this.metadata.get(entityName); |
| 2028 | const data = (mapped ? result : this.driver.mapResult(result, meta)) as Dictionary; |
| 2029 | |
| 2030 | for (const k of Object.keys(data)) { |
| 2031 | const prop = meta.properties[k as EntityKey<Entity>]; |
| 2032 | |
| 2033 | if ( |
| 2034 | prop?.kind === ReferenceKind.SCALAR && |
| 2035 | SCALAR_TYPES.has(prop.runtimeType) && |
| 2036 | !prop.customType && |
| 2037 | (prop.setter || !prop.getter) |
| 2038 | ) { |
| 2039 | validateProperty(prop, data[k], data); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | return this.merge<Entity>(entityName, data as EntityData<Entity>, { |
| 2044 | convertCustomTypes: true, |
| 2045 | refresh: true, |
| 2046 | validate: false, |
| 2047 | ...rest, |
| 2048 | }); |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities |