@simplysm/sd-orm-common
Advanced tools
Comparing version 11.0.15 to 11.0.16
@@ -27,2 +27,3 @@ import { QueryBuilder } from "./QueryBuilder"; | ||
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
executePreparedAsync(): Promise<void>; | ||
@@ -29,0 +30,0 @@ getIsDbExistsAsync(database?: string): Promise<boolean>; |
@@ -141,2 +141,7 @@ import { QueryBuilder } from "./QueryBuilder"; | ||
} | ||
async bulkUpsertAsync(tableName, columnDefs, records) { | ||
if (!this._executor) | ||
throw new Error("DB 실행기를 알 수 없습니다."); | ||
await this._executor.bulkUpsertAsync(tableName, columnDefs, records); | ||
} | ||
async executePreparedAsync() { | ||
@@ -143,0 +148,0 @@ if (this.prepareDefs.length < 1) |
@@ -15,2 +15,3 @@ /// <reference types="node" /> | ||
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
} |
@@ -16,3 +16,4 @@ import { IQueryColumnDef, IQueryResultParseOption, ISOLATION_LEVEL, TQueryDef } from "./commons"; | ||
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
closeAsync(): Promise<void>; | ||
} |
@@ -62,3 +62,4 @@ import { DbContext } from "./DbContext"; | ||
existsAsync(): Promise<boolean>; | ||
bulkInsertAsync(arg: TInsertObject<T> | (TInsertObject<T>[])): Promise<void>; | ||
bulkInsertAsync(records: TInsertObject<T>[]): Promise<void>; | ||
bulkUpsertAsync(records: TInsertObject<T>[]): Promise<void>; | ||
insertAsync(records: TInsertObject<T>[]): Promise<void>; | ||
@@ -65,0 +66,0 @@ insertAsync<OK extends keyof T>(records: TInsertObject<T>[], outputColumns: OK[]): Promise<{ |
@@ -802,4 +802,3 @@ import { FunctionUtil, NeverEntryError, ObjectUtil } from "@simplysm/sd-core-common"; | ||
} | ||
async bulkInsertAsync(arg) { | ||
const records = arg instanceof Array ? arg : [arg]; | ||
async bulkInsertAsync(records) { | ||
if (records.length === 0) | ||
@@ -815,2 +814,3 @@ return; | ||
const columnDefs = this.tableDef.columns.map((col) => ({ | ||
primaryKey: col.primaryKey, | ||
name: col.name, | ||
@@ -829,2 +829,30 @@ dataType: this.db.qh.type(col.dataType ?? col.typeFwd()), | ||
} | ||
async bulkUpsertAsync(records) { | ||
if (records.length === 0) | ||
return; | ||
if (typeof this.db === "undefined") { | ||
throw new Error("'DbContext'가 설정되지 않은 쿼리는 실행할 수 없습니다."); | ||
} | ||
if (this.db.opt.dialect !== "mysql") { | ||
throw new Error("'bulkUpsert'는 'MYSQL'에서만 지원됩니다."); | ||
} | ||
// DbContext.selectCache.clear(); | ||
if (!this.tableDef) { | ||
throw new Error("'Wrapping'된 이후에는 테이블의 정보를 가져올 수 없습니다."); | ||
} | ||
const columnDefs = this.tableDef.columns.map((col) => ({ | ||
primaryKey: col.primaryKey, | ||
name: col.name, | ||
dataType: this.db.qh.type(col.dataType ?? col.typeFwd()), | ||
autoIncrement: col.autoIncrement, | ||
nullable: col.nullable | ||
})); | ||
await this.db.bulkUpsertAsync(this.tableName, columnDefs, records.map((item) => { | ||
const result = {}; | ||
for (const key of Object.keys(item)) { | ||
result[key] = this.db.qh.getBulkInsertQueryValue(item[key]); | ||
} | ||
return result; | ||
})); | ||
} | ||
async insertAsync(records, outputColumns) { | ||
@@ -831,0 +859,0 @@ return await this._insertAsync(false, records, outputColumns); |
@@ -809,3 +809,3 @@ import { NeverEntryError, Uuid } from "@simplysm/sd-core-common"; | ||
SET foreign_key_checks=0; | ||
/*SET foreign_key_checks=0;*/ | ||
@@ -827,3 +827,3 @@ SET @cols = NULL; | ||
SET foreign_key_checks=1;`.trim(); | ||
/*SET foreign_key_checks=1;*/`.trim(); | ||
} | ||
@@ -830,0 +830,0 @@ else { |
{ | ||
"name": "@simplysm/sd-orm-common", | ||
"version": "11.0.15", | ||
"version": "11.0.16", | ||
"description": "심플리즘 패키지 - ORM 모듈 (common)", | ||
@@ -19,4 +19,4 @@ "author": "김석래", | ||
"dependencies": { | ||
"@simplysm/sd-core-common": "11.0.15" | ||
"@simplysm/sd-core-common": "11.0.16" | ||
} | ||
} |
@@ -175,2 +175,7 @@ import {QueryBuilder} from "./QueryBuilder"; | ||
public async bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]) { | ||
if (!this._executor) throw new Error("DB 실행기를 알 수 없습니다."); | ||
await this._executor.bulkUpsertAsync(tableName, columnDefs, records); | ||
} | ||
public async executePreparedAsync(): Promise<void> { | ||
@@ -177,0 +182,0 @@ if (this.prepareDefs.length < 1) return; |
@@ -22,2 +22,4 @@ import {EventEmitter} from "events"; | ||
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
} |
@@ -25,4 +25,6 @@ import {IQueryColumnDef, IQueryResultParseOption, ISOLATION_LEVEL, TQueryDef} from "./commons"; | ||
bulkUpsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>; | ||
closeAsync(): Promise<void>; | ||
} | ||
@@ -970,3 +970,3 @@ import { | ||
SET foreign_key_checks=0; | ||
/*SET foreign_key_checks=0;*/ | ||
@@ -988,3 +988,3 @@ SET @cols = NULL; | ||
SET foreign_key_checks=1;`.trim(); | ||
/*SET foreign_key_checks=1;*/`.trim(); | ||
} | ||
@@ -991,0 +991,0 @@ else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
568235
9869
+ Added@simplysm/sd-core-common@11.0.16(transitive)
- Removed@simplysm/sd-core-common@11.0.15(transitive)