|
|
|
@ -2478,6 +2478,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
skip_hooks = false, |
|
|
|
|
raw = false, |
|
|
|
|
insertOneByOneAsFallback = false, |
|
|
|
|
isSingleRecordInsertion = false, |
|
|
|
|
}: { |
|
|
|
|
chunkSize?: number; |
|
|
|
|
cookie?: any; |
|
|
|
@ -2485,6 +2486,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
skip_hooks?: boolean; |
|
|
|
|
raw?: boolean; |
|
|
|
|
insertOneByOneAsFallback?: boolean; |
|
|
|
|
isSingleRecordInsertion?: boolean; |
|
|
|
|
} = {}, |
|
|
|
|
) { |
|
|
|
|
let trx; |
|
|
|
@ -2671,8 +2673,14 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
await trx.commit(); |
|
|
|
|
|
|
|
|
|
if (!raw && !skip_hooks) |
|
|
|
|
await this.afterBulkInsert(insertDatas, this.dbDriver, cookie); |
|
|
|
|
if (!raw && !skip_hooks) { |
|
|
|
|
if (isSingleRecordInsertion) { |
|
|
|
|
const insertData = await this.readByPk(response[0]); |
|
|
|
|
await this.afterInsert(insertData, this.dbDriver, cookie); |
|
|
|
|
} else { |
|
|
|
|
await this.afterBulkInsert(insertDatas, this.dbDriver, cookie); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return response; |
|
|
|
|
} catch (e) { |
|
|
|
@ -2688,7 +2696,13 @@ class BaseModelSqlv2 {
|
|
|
|
|
cookie, |
|
|
|
|
raw = false, |
|
|
|
|
throwExceptionIfNotExist = false, |
|
|
|
|
}: { cookie?: any; raw?: boolean; throwExceptionIfNotExist?: boolean } = {}, |
|
|
|
|
isSingleRecordUpdation = false, |
|
|
|
|
}: { |
|
|
|
|
cookie?: any; |
|
|
|
|
raw?: boolean; |
|
|
|
|
throwExceptionIfNotExist?: boolean; |
|
|
|
|
isSingleRecordUpdation?: boolean; |
|
|
|
|
} = {}, |
|
|
|
|
) { |
|
|
|
|
let transaction; |
|
|
|
|
try { |
|
|
|
@ -2740,8 +2754,19 @@ class BaseModelSqlv2 {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!raw) |
|
|
|
|
await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie); |
|
|
|
|
if (!raw) { |
|
|
|
|
if (isSingleRecordUpdation) { |
|
|
|
|
await this.afterUpdate( |
|
|
|
|
prevData[0], |
|
|
|
|
newData[0], |
|
|
|
|
trx, |
|
|
|
|
cookie, |
|
|
|
|
datas[0], |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
|
} catch (e) { |
|
|
|
@ -2816,7 +2841,12 @@ class BaseModelSqlv2 {
|
|
|
|
|
{ |
|
|
|
|
cookie, |
|
|
|
|
throwExceptionIfNotExist = false, |
|
|
|
|
}: { cookie?: any; throwExceptionIfNotExist?: boolean } = {}, |
|
|
|
|
isSingleRecordDeletion = false, |
|
|
|
|
}: { |
|
|
|
|
cookie?: any; |
|
|
|
|
throwExceptionIfNotExist?: boolean; |
|
|
|
|
isSingleRecordDeletion?: boolean; |
|
|
|
|
} = {}, |
|
|
|
|
) { |
|
|
|
|
let transaction; |
|
|
|
|
try { |
|
|
|
@ -2918,7 +2948,11 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
await transaction.commit(); |
|
|
|
|
|
|
|
|
|
await this.afterBulkDelete(deleted, this.dbDriver, cookie); |
|
|
|
|
if (isSingleRecordDeletion) { |
|
|
|
|
await this.afterDelete(deleted[0], trx, cookie); |
|
|
|
|
} else { |
|
|
|
|
await this.afterBulkDelete(deleted, this.dbDriver, cookie); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
|
} catch (e) { |
|
|
|
@ -4618,6 +4652,11 @@ function applyPaginate(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function _wherePk(primaryKeys: Column[], id: unknown | unknown[]) { |
|
|
|
|
// if id object is provided use as it is
|
|
|
|
|
if (id && typeof id === 'object') { |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ids = Array.isArray(id) ? id : (id + '').split('___'); |
|
|
|
|
const where = {}; |
|
|
|
|
for (let i = 0; i < primaryKeys.length; ++i) { |
|
|
|
|