Skip to content

Commit 358cb74

Browse files
author
Michael Liebmann
committed
Updated naming of params and keys
1 parent c1b2705 commit 358cb74

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/actions/updateSpecificFieldOfRecord.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const actionDefinition: ActionDefinition = {
2020
{
2121
key: 'updateQuery',
2222
name: 'Update Query Template',
23-
description: 'SQL UPDATE query template with {record} and {value} placeholders',
23+
description: 'SQL UPDATE query template with {record_id} and {new_value} placeholders',
2424
type: 'string',
2525
validation: {
2626
required: true,
@@ -89,9 +89,10 @@ export async function handler({ input }: ActionContext): Promise<OutputObject> {
8989

9090
const updateQuery = constructUpdateQuery(
9191
input.updateQuery,
92-
input.record,
93-
input.updateValue
92+
input.recordId,
93+
input.newValue
9494
);
95+
9596
const result = await executeTransaction(client, updateQuery);
9697

9798
return {
@@ -146,16 +147,16 @@ function formatQueryResponse(updateQuery: string): string {
146147
return updateQuery;
147148
}
148149

149-
function constructUpdateQuery(queryTemplate: string, record: string, value: string): string {
150+
function constructUpdateQuery(queryTemplate: string, recordId: string, newValue: string): string {
150151
// Validate that the template contains both placeholders
151-
if (!queryTemplate.includes('{record}') || !queryTemplate.includes('{value}')) {
152-
throw new Error('Update query template must contain both {record} and {value} placeholders');
152+
if (!queryTemplate.includes('{record_id}') || !queryTemplate.includes('{new_value}')) {
153+
throw new Error('Update query template must contain both {record_id} and {new_value} placeholders');
153154
}
154155

155156
// Use String.prototype.replace with a replacer function to preserve case
156157
const updateStatement = queryTemplate
157-
.replace(/{record}/g, (match) => `'${record}'`) // Preserve case of record
158-
.replace(/{value}/g, (match) => `'${value}'`); // Preserve case of value
158+
.replace(/{record_id}/g, (match) => `'${recordId}'`)
159+
.replace(/{new_value}/g, (match) => `'${newValue}'`);
159160

160161
// Extract the WHERE clause to use in the SELECT statement
161162
const whereClauseMatch = updateStatement.match(/WHERE\s+(.+)$/i);

0 commit comments

Comments
 (0)