@simplysm/sd-orm-common
Advanced tools
Comparing version 11.2.3 to 11.3.1
@@ -248,2 +248,4 @@ import { TFlatType, Type, UnwrappedType, WrappedType } from "@simplysm/sd-core-common"; | ||
output?: string[]; | ||
aiKeyName?: string; | ||
pkColNames: string[]; | ||
} | ||
@@ -250,0 +252,0 @@ export interface ITruncateTableQueryDef { |
@@ -55,3 +55,3 @@ import { DbContext } from "./DbContext"; | ||
getInsertIfNotExistsQueryDef(insertObj: TInsertObject<T>, outputColumns: (keyof T)[] | undefined): IInsertIfNotExistsQueryDef; | ||
getUpsertQueryDef<U extends TUpdateObject<T>>(updateObj: U, insertObj: TInsertObject<T> | undefined, outputColumns: (keyof T)[] | undefined): IUpsertQueryDef; | ||
getUpsertQueryDef<U extends TUpdateObject<T>>(updateObj: U, insertObj: TInsertObject<T> | undefined, outputColumns: (keyof T)[] | undefined, aiKeyName: string | undefined, pkColNames: string[]): IUpsertQueryDef; | ||
getDeleteQueryDef(outputColumns: (keyof T)[] | undefined): IDeleteQueryDef; | ||
@@ -58,0 +58,0 @@ insertIntoAsync(tableType: Type<T>): Promise<void>; |
@@ -631,3 +631,3 @@ import { FunctionUtil, NeverEntryError, ObjectUtil } from "@simplysm/sd-core-common"; | ||
} | ||
getUpsertQueryDef(updateObj, insertObj, outputColumns) { | ||
getUpsertQueryDef(updateObj, insertObj, outputColumns, aiKeyName, pkColNames) { | ||
if (this._def.join !== undefined) { | ||
@@ -684,3 +684,5 @@ throw new Error("UPSERT 와 JOIN 를 함께 사용할 수 없습니다."); | ||
insertRecord, | ||
output: outputColumns?.map((item) => this.db.qb.wrap(item)) | ||
output: outputColumns?.map((item) => this.db.qb.wrap(item)), | ||
aiKeyName, | ||
pkColNames | ||
}); | ||
@@ -1262,7 +1264,8 @@ } | ||
// DbContext.selectCache.clear(); | ||
// const pkColNames = this.tableDef.columns.filter((item) => item.primaryKey !== undefined).map((item) => item.name); | ||
const pkColNames = this.tableDef.columns.filter((item) => item.primaryKey !== undefined).map((item) => item.name); | ||
const aiColNames = this.tableDef.columns.filter((item) => item.autoIncrement).map((item) => item.name); | ||
let dataIndex; | ||
// let dataIndex: number; | ||
const defs = []; | ||
const queryDef = this.getUpsertQueryDef(updateRecord, insertRecord, outputColumns); | ||
const aiKeyName = pkColNames.single(item => aiColNames.includes(item)); | ||
const queryDef = this.getUpsertQueryDef(updateRecord, insertRecord, outputColumns, aiKeyName, pkColNames); | ||
defs.push({ | ||
@@ -1272,34 +1275,36 @@ type: "upsert", | ||
}); | ||
if (this.db.opt.dialect === "mysql" && outputColumns) { | ||
const selectObj = outputColumns.toObject((colName) => this.db.qb.wrap(colName), (colName) => this.db.qb.wrap(colName)); | ||
// if ( | ||
// pkColNames.length === 1 && aiColNames.length === 1 | ||
// && pkColNames[0] === aiColNames[0] | ||
// && !Object.keys(insertRecord).includes(aiColNames[0]) | ||
// ) { | ||
// const pkColName = pkColNames[0]; | ||
// defs.push({ | ||
// type: "select" as const, | ||
// ...this.getSelectQueryDef(), | ||
// select: selectObj, | ||
// where: [[this.db.qb.wrap(pkColName), " = ", "LAST_INSERT_ID()"]] | ||
// }); | ||
// } | ||
// else { | ||
// defs.push({ | ||
// type: "select" as const, | ||
// ...this.getSelectQueryDef(), | ||
// select: selectObj | ||
// }); | ||
// } | ||
defs.push({ | ||
type: "select", | ||
...this.getSelectQueryDef(), | ||
select: selectObj | ||
}); | ||
dataIndex = 1; | ||
/*if (this.db.opt.dialect === "mysql" && outputColumns) { | ||
const selectObj = outputColumns.toObject((colName) => this.db.qb.wrap(colName as string), (colName) => this.db.qb.wrap(colName as string)); | ||
// if ( | ||
// pkColNames.length === 1 && aiColNames.length === 1 | ||
// && pkColNames[0] === aiColNames[0] | ||
// && !Object.keys(insertRecord).includes(aiColNames[0]) | ||
// ) { | ||
// const pkColName = pkColNames[0]; | ||
// defs.push({ | ||
// type: "select" as const, | ||
// ...this.getSelectQueryDef(), | ||
// select: selectObj, | ||
// where: [[this.db.qb.wrap(pkColName), " = ", "LAST_INSERT_ID()"]] | ||
// }); | ||
// } | ||
// else { | ||
// defs.push({ | ||
// type: "select" as const, | ||
// ...this.getSelectQueryDef(), | ||
// select: selectObj | ||
// }); | ||
// } | ||
defs.push({ | ||
type: "select" as const, | ||
...this.getSelectQueryDef(), | ||
select: selectObj | ||
}); | ||
dataIndex = 1; | ||
} | ||
else { | ||
dataIndex = 0; | ||
} | ||
dataIndex = 0; | ||
}*/ | ||
let dataIndex = 0; | ||
if (this.db.opt.dialect !== "mysql") { | ||
@@ -1306,0 +1311,0 @@ const hasSomeAIColVal = Object.keys(insertRecord).some((item) => aiColNames.includes(item)); |
@@ -761,2 +761,4 @@ import { NeverEntryError, Uuid } from "@simplysm/sd-core-common"; | ||
${def.output ? this.select(def) + ";" : ""} | ||
ELSE | ||
@@ -766,2 +768,8 @@ | ||
${def.output ? (this.select({ | ||
...def, | ||
where: def.pkColNames.map(pkColName => (pkColName === def.aiKeyName ? [this.wrap(def.aiKeyName), " = ", "LAST_INSERT_ID()"] | ||
: [this.wrap(pkColName), " = ", this.getQueryOfQueryValue(def.insertRecord[this.wrap(pkColName)])])) | ||
})) + ";" : ""} | ||
END IF; | ||
@@ -768,0 +776,0 @@ |
@@ -63,3 +63,3 @@ import { DateOnly, DateTime, JsonConvert, Time, Uuid } from "@simplysm/sd-core-common"; | ||
// 타입 변환 | ||
const data = orgResults.map((item) => { | ||
const data = orgResults.flat().map((item) => { | ||
const obj = {}; | ||
@@ -66,0 +66,0 @@ for (const key of Object.keys(item)) { |
{ | ||
"name": "@simplysm/sd-orm-common", | ||
"version": "11.2.3", | ||
"version": "11.3.1", | ||
"description": "심플리즘 패키지 - ORM 모듈 (common)", | ||
@@ -19,4 +19,4 @@ "author": "김석래", | ||
"dependencies": { | ||
"@simplysm/sd-core-common": "11.2.3" | ||
"@simplysm/sd-core-common": "11.3.1" | ||
} | ||
} |
@@ -280,2 +280,4 @@ import {TFlatType, Type, UnwrappedType, WrappedType} from "@simplysm/sd-core-common"; | ||
output?: string[]; | ||
aiKeyName?: string; | ||
pkColNames: string[]; | ||
} | ||
@@ -282,0 +284,0 @@ |
@@ -914,2 +914,4 @@ import { | ||
${def.output ? this.select(def) + ";" : ""} | ||
ELSE | ||
@@ -919,2 +921,12 @@ | ||
${def.output ? ( | ||
this.select({ | ||
...def, | ||
where: def.pkColNames.map(pkColName => ( | ||
pkColName === def.aiKeyName ? [this.wrap(def.aiKeyName), " = ", "LAST_INSERT_ID()"] | ||
: [this.wrap(pkColName), " = ", this.getQueryOfQueryValue(def.insertRecord[this.wrap(pkColName)])] | ||
)) | ||
}) | ||
) + ";" : ""} | ||
END IF; | ||
@@ -921,0 +933,0 @@ |
@@ -69,3 +69,3 @@ import {IQueryResultParseOption, TEntity, TEntityValue, TQueryValue} from "../commons"; | ||
// 타입 변환 | ||
const data: Record<string, any>[] = orgResults.map((item) => { | ||
const data: Record<string, any>[] = orgResults.flat().map((item) => { | ||
const obj: Record<string, any> = {}; | ||
@@ -72,0 +72,0 @@ for (const key of Object.keys(item)) { |
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
572545
9940
+ Added@simplysm/sd-core-common@11.3.1(transitive)
- Removed@simplysm/sd-core-common@11.2.3(transitive)