Updates
This commit is contained in:
parent
a10524da95
commit
a915be704b
@ -17,6 +17,7 @@ type Param<T extends {
|
||||
debug?: boolean;
|
||||
dbConfig?: ConnectionConfig;
|
||||
whereClauseObject?: DsqlCrudParamWhereClause;
|
||||
targetIds?: (string | number)[];
|
||||
};
|
||||
/**
|
||||
* # Update DB Function
|
||||
@ -24,5 +25,5 @@ type Param<T extends {
|
||||
*/
|
||||
export default function updateDbEntry<T extends {
|
||||
[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 {};
|
||||
|
||||
@ -24,7 +24,7 @@ const grab_parsed_value_1 = __importDefault(require("./grab-parsed-value"));
|
||||
* @description
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* Check if data is valid
|
||||
@ -97,7 +97,11 @@ function updateDbEntry(_a) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
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}`;
|
||||
updateValues.push(...(whereClauseObject.params || []));
|
||||
}
|
||||
|
||||
@ -70,6 +70,7 @@ function dsqlCrud(params) {
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
whereClauseObject,
|
||||
targetIds,
|
||||
});
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
|
||||
@ -27,6 +27,7 @@ type Param<T extends { [k: string]: any } = any> = {
|
||||
debug?: boolean;
|
||||
dbConfig?: ConnectionConfig;
|
||||
whereClauseObject?: DsqlCrudParamWhereClause;
|
||||
targetIds?: (string | number)[];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -49,6 +50,7 @@ export default async function updateDbEntry<
|
||||
debug,
|
||||
dbConfig,
|
||||
whereClauseObject,
|
||||
targetIds,
|
||||
}: Param<T>): Promise<APIResponseObject<PostInsertReturn>> {
|
||||
/**
|
||||
* Check if data is valid
|
||||
@ -142,7 +144,10 @@ export default async function updateDbEntry<
|
||||
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}`;
|
||||
updateValues.push(...(whereClauseObject.params || []));
|
||||
} else {
|
||||
|
||||
@ -94,6 +94,7 @@ export default async function dsqlCrud<
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
whereClauseObject,
|
||||
targetIds,
|
||||
});
|
||||
|
||||
return UPDATE_RESULT;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.7.23",
|
||||
"version": "5.7.24",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user