Updates
This commit is contained in:
parent
a10524da95
commit
a915be704b
@ -17,6 +17,7 @@ type Param<T extends {
|
|||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
dbConfig?: ConnectionConfig;
|
dbConfig?: ConnectionConfig;
|
||||||
whereClauseObject?: DsqlCrudParamWhereClause;
|
whereClauseObject?: DsqlCrudParamWhereClause;
|
||||||
|
targetIds?: (string | number)[];
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Update DB Function
|
* # Update DB Function
|
||||||
@ -24,5 +25,5 @@ type Param<T extends {
|
|||||||
*/
|
*/
|
||||||
export default function updateDbEntry<T extends {
|
export default function updateDbEntry<T extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = any>({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, whereClauseObject, }: Param<T>): Promise<APIResponseObject<PostInsertReturn>>;
|
} = any>({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, whereClauseObject, targetIds, }: Param<T>): Promise<APIResponseObject<PostInsertReturn>>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@ -24,7 +24,7 @@ const grab_parsed_value_1 = __importDefault(require("./grab-parsed-value"));
|
|||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
function updateDbEntry(_a) {
|
function updateDbEntry(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, whereClauseObject, }) {
|
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, debug, dbConfig, whereClauseObject, targetIds, }) {
|
||||||
var _b, _c;
|
var _b, _c;
|
||||||
/**
|
/**
|
||||||
* Check if data is valid
|
* Check if data is valid
|
||||||
@ -97,7 +97,11 @@ function updateDbEntry(_a) {
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
let query = `UPDATE ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` SET ${updateKeyValueArray.join(",")}`;
|
let query = `UPDATE ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` SET ${updateKeyValueArray.join(",")}`;
|
||||||
if (whereClauseObject) {
|
if (targetIds) {
|
||||||
|
query += ` WHERE id IN (${targetIds.map((id) => "?").join(",")})`;
|
||||||
|
updateValues = targetIds;
|
||||||
|
}
|
||||||
|
else if (whereClauseObject) {
|
||||||
query += ` ${whereClauseObject.clause}`;
|
query += ` ${whereClauseObject.clause}`;
|
||||||
updateValues.push(...(whereClauseObject.params || []));
|
updateValues.push(...(whereClauseObject.params || []));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,6 +70,7 @@ function dsqlCrud(params) {
|
|||||||
tableSchema,
|
tableSchema,
|
||||||
dbConfig,
|
dbConfig,
|
||||||
whereClauseObject,
|
whereClauseObject,
|
||||||
|
targetIds,
|
||||||
});
|
});
|
||||||
return UPDATE_RESULT;
|
return UPDATE_RESULT;
|
||||||
case "delete":
|
case "delete":
|
||||||
|
|||||||
@ -27,6 +27,7 @@ type Param<T extends { [k: string]: any } = any> = {
|
|||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
dbConfig?: ConnectionConfig;
|
dbConfig?: ConnectionConfig;
|
||||||
whereClauseObject?: DsqlCrudParamWhereClause;
|
whereClauseObject?: DsqlCrudParamWhereClause;
|
||||||
|
targetIds?: (string | number)[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +50,7 @@ export default async function updateDbEntry<
|
|||||||
debug,
|
debug,
|
||||||
dbConfig,
|
dbConfig,
|
||||||
whereClauseObject,
|
whereClauseObject,
|
||||||
|
targetIds,
|
||||||
}: Param<T>): Promise<APIResponseObject<PostInsertReturn>> {
|
}: Param<T>): Promise<APIResponseObject<PostInsertReturn>> {
|
||||||
/**
|
/**
|
||||||
* Check if data is valid
|
* Check if data is valid
|
||||||
@ -142,7 +144,10 @@ export default async function updateDbEntry<
|
|||||||
isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`
|
isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`
|
||||||
}\`${tableName}\` SET ${updateKeyValueArray.join(",")}`;
|
}\`${tableName}\` SET ${updateKeyValueArray.join(",")}`;
|
||||||
|
|
||||||
if (whereClauseObject) {
|
if (targetIds) {
|
||||||
|
query += ` WHERE id IN (${targetIds.map((id) => "?").join(",")})`;
|
||||||
|
updateValues = targetIds;
|
||||||
|
} else if (whereClauseObject) {
|
||||||
query += ` ${whereClauseObject.clause}`;
|
query += ` ${whereClauseObject.clause}`;
|
||||||
updateValues.push(...(whereClauseObject.params || []));
|
updateValues.push(...(whereClauseObject.params || []));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -94,6 +94,7 @@ export default async function dsqlCrud<
|
|||||||
tableSchema,
|
tableSchema,
|
||||||
dbConfig,
|
dbConfig,
|
||||||
whereClauseObject,
|
whereClauseObject,
|
||||||
|
targetIds,
|
||||||
});
|
});
|
||||||
|
|
||||||
return UPDATE_RESULT;
|
return UPDATE_RESULT;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.7.23",
|
"version": "5.7.24",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user