修改无用代码

This commit is contained in:
cool 2024-04-23 14:35:40 +08:00
parent fc23c816b2
commit 8deaa90fd4
5 changed files with 57 additions and 51 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/core", "name": "@cool-midway/core",
"version": "7.1.16", "version": "7.1.17",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "index.d.ts", "typings": "index.d.ts",

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/core", "name": "@cool-midway/core",
"version": "7.1.16", "version": "7.1.17",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"typings": "index.d.ts", "typings": "index.d.ts",

View File

@ -447,7 +447,7 @@ export abstract class BaseMysqlService {
} }
// 单表字段无别名的情况下操作 // 单表字段无别名的情况下操作
if (typeof key === "string") { if (typeof key === "string") {
if (query[key] || (query[key] == 0 && query[key] == "")) { if (query[key] || (query[key] == 0 && query[key] != "")) {
c[key] = query[key]; c[key] = query[key];
const eq = query[key] instanceof Array ? "in" : "="; const eq = query[key] instanceof Array ? "in" : "=";
if (eq === "in") { if (eq === "in") {

View File

@ -509,7 +509,7 @@ export abstract class BasePgService {
} }
// 单表字段无别名的情况下操作 // 单表字段无别名的情况下操作
if (typeof key === "string") { if (typeof key === "string") {
if (query[key] || (query[key] == 0 && query[key] == "")) { if (query[key] || (query[key] == 0 && query[key] != "")) {
c[key] = query[key]; c[key] = query[key];
const eq = query[key] instanceof Array ? "in" : "="; const eq = query[key] instanceof Array ? "in" : "=";
if (eq === "in") { if (eq === "in") {

View File

@ -75,17 +75,17 @@ export abstract class BaseSqliteService {
// 将这个? 替换成 $1,$2,$3 // 将这个? 替换成 $1,$2,$3
const replaceStr = []; const replaceStr = [];
for (let j = 0; j < param.length; j++) { for (let j = 0; j < param.length; j++) {
replaceStr.push('$' + (this.sqlParams.length + j + 1)); replaceStr.push("$" + (this.sqlParams.length + j + 1));
} }
this.sqlParams = this.sqlParams.concat(...params); this.sqlParams = this.sqlParams.concat(...params);
sql = sql.replace('?', replaceStr.join(',')); sql = sql.replace("?", replaceStr.join(","));
} else { } else {
sql = sql.replace('?', '$' + (this.sqlParams.length + 1)); sql = sql.replace("?", "$" + (this.sqlParams.length + 1));
this.sqlParams.push(param); this.sqlParams.push(param);
} }
} }
} }
return (rSql ? sql : "").replace(/\$\d+/g, '?'); return (rSql ? sql : "").replace(/\$\d+/g, "?");
} }
/** /**
@ -135,17 +135,20 @@ export abstract class BaseSqliteService {
if (item instanceof Array) { if (item instanceof Array) {
const replaceStr = []; const replaceStr = [];
for (let i = 0; i < item.length; i++) { for (let i = 0; i < item.length; i++) {
replaceStr.push('$' + (newParams.length + i + 1)); replaceStr.push("$" + (newParams.length + i + 1));
} }
newParams.push(...item) newParams.push(...item);
sql = sql.replace('?', replaceStr.join(',')); sql = sql.replace("?", replaceStr.join(","));
} else { } else {
sql = sql.replace('?', '$' + (newParams.length + 1)); sql = sql.replace("?", "$" + (newParams.length + 1));
newParams.push(item); newParams.push(item);
} }
} }
this.sqlParams = []; this.sqlParams = [];
return await this.getOrmManager(connectionName).query(sql.replace(/\$\d+/g, '?'), newParams || []); return await this.getOrmManager(connectionName).query(
sql.replace(/\$\d+/g, "?"),
newParams || []
);
} }
/** /**
@ -325,7 +328,7 @@ export abstract class BaseSqliteService {
* | * |
* @param param * @param param
*/ */
async addOrUpdate(param: any | any[], type: 'add' | 'update' = 'add') { async addOrUpdate(param: any | any[], type: "add" | "update" = "add") {
if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY); if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY);
delete param.createTime; delete param.createTime;
// 判断是否是批量操作 // 判断是否是批量操作
@ -336,22 +339,26 @@ export abstract class BaseSqliteService {
}); });
await this.entity.save(param); await this.entity.save(param);
} else { } else {
const upsert = this._coolConfig.crud?.upsert || 'normal'; const upsert = this._coolConfig.crud?.upsert || "normal";
if (type == 'update') { if (type == "update") {
if(upsert == 'save') { if (upsert == "save") {
const info = await this.entity.findOneBy({id: param.id}) const info = await this.entity.findOneBy({ id: param.id });
param = { param = {
...info, ...info,
...param ...param,
} };
} }
param.updateTime = new Date(); param.updateTime = new Date();
upsert == 'normal'? await this.entity.update(param.id, param): await this.entity.save(param); upsert == "normal"
? await this.entity.update(param.id, param)
: await this.entity.save(param);
} }
if(type =='add'){ if (type == "add") {
param.createTime = new Date(); param.createTime = new Date();
param.updateTime = new Date(); param.updateTime = new Date();
upsert == 'normal'? await this.entity.insert(param): await this.entity.save(param); upsert == "normal"
? await this.entity.insert(param)
: await this.entity.save(param);
} }
} }
} }
@ -466,14 +473,14 @@ export abstract class BaseSqliteService {
for (let key of option.fieldEq) { for (let key of option.fieldEq) {
const c = {}; const c = {};
// 如果key有包含.的情况下操作 // 如果key有包含.的情况下操作
if(typeof key === "string" && key.includes('.')){ if (typeof key === "string" && key.includes(".")) {
const keys = key.split('.'); const keys = key.split(".");
const lastKey = keys.pop(); const lastKey = keys.pop();
key = { requestParam: lastKey, column: key }; key = { requestParam: lastKey, column: key };
} }
// 单表字段无别名的情况下操作 // 单表字段无别名的情况下操作
if (typeof key === "string") { if (typeof key === "string") {
if (query[key] || (query[key] == 0 && query[key] == "")) { if (query[key] || (query[key] == 0 && query[key] != "")) {
c[key] = query[key]; c[key] = query[key];
const eq = query[key] instanceof Array ? "in" : "="; const eq = query[key] instanceof Array ? "in" : "=";
if (eq === "in") { if (eq === "in") {
@ -526,5 +533,4 @@ export abstract class BaseSqliteService {
sqlArr.push(sqls[sqls.length - 1]); sqlArr.push(sqls[sqls.length - 1]);
return sqlArr.join(" "); return sqlArr.join(" ");
} }
} }