(
entityName: EntityName<T>,
data: EntityDictionary<T>,
options: NativeInsertUpdateOptions<T> = {},
)
| 925 | } |
| 926 | |
| 927 | async nativeInsert<T extends object>( |
| 928 | entityName: EntityName<T>, |
| 929 | data: EntityDictionary<T>, |
| 930 | options: NativeInsertUpdateOptions<T> = {}, |
| 931 | ): Promise<QueryResult<T>> { |
| 932 | options.convertCustomTypes ??= true; |
| 933 | const meta = this.metadata.get(entityName); |
| 934 | const collections = this.extractManyToMany(meta, data); |
| 935 | const qb = this.createQueryBuilder( |
| 936 | entityName, |
| 937 | options.ctx, |
| 938 | 'write', |
| 939 | options.convertCustomTypes, |
| 940 | options.loggerContext, |
| 941 | ).withSchema(this.getSchemaName(meta, options)); |
| 942 | qb.setAbortOptions(pickAbortOptions(options)); |
| 943 | const res = await this.rethrow(qb.insert(data as unknown as RequiredEntityData<T>).execute('run', false)); |
| 944 | res.row = res.row || {}; |
| 945 | let pk: any; |
| 946 | |
| 947 | if (meta.primaryKeys.length > 1) { |
| 948 | // owner has composite pk |
| 949 | pk = Utils.getPrimaryKeyCond(data as T, meta.primaryKeys); |
| 950 | } else { |
| 951 | /* v8 ignore next */ |
| 952 | res.insertId = data[meta.primaryKeys[0]] ?? res.insertId ?? res.row[meta.primaryKeys[0]]; |
| 953 | |
| 954 | if (options.convertCustomTypes && meta?.getPrimaryProp().customType) { |
| 955 | pk = [meta!.getPrimaryProp().customType!.convertToDatabaseValue(res.insertId, this.platform)]; |
| 956 | } else { |
| 957 | pk = [res.insertId]; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | await this.processManyToMany(meta, pk, collections, false, options); |
| 962 | |
| 963 | return res; |
| 964 | } |
| 965 | |
| 966 | override async nativeClone<T extends object>( |
| 967 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected