Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.2 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { oracleDbAuth } from '../common/auth';
import { OracleDbClient } from '../common/client';
import { oracleDbProps } from '../common/props';

export const updateRowAction = createAction({
  auth: oracleDbAuth,
  name: 'update_row',
  classification: 'WRITE',
  displayName: 'Update Row',
  description: 'Update rows in an Oracle table',
  audience: 'both',
  aiMetadata: { description: 'Updates rows in an Oracle Database table, setting the given column values on every row that matches the filter (WHERE) conditions. Use to modify existing records. Critical: an empty filter object updates ALL rows in the table, so always scope the filter unless a full-table update is intended. Repeating the same call re-applies the same values (effectively idempotent for fixed values), but counts as a mutation each time.', idempotent: false },
  props: {
    tableName: oracleDbProps.tableName(),
    values: Property.Object({
      displayName: 'Values',
      description: 'Column names and new values to set',
      required: true,
      defaultValue: { SALARY: 8000 },
    }),
    filter: Property.Object({
      displayName: 'Filter (WHERE)',
      description: 'Conditions to match rows. Empty object updates ALL rows.',
      required: true,
      defaultValue: { ID: 101 },
    }),
  },
  async run(context) {
    const { tableName, values, filter } = context.propsValue;

    if (
      typeof values !== 'object' ||
      values === null ||
      Array.isArray(values) ||
      Object.keys(values).length === 0
    ) {
      throw new Error('Values must be a non-empty object');
    }
    if (
      typeof filter !== 'object' ||
      filter === null ||
      Array.isArray(filter)
    ) {
      throw new Error('Filter must be a valid object');
    }

    try {
      const client = new OracleDbClient(context.auth.props);
      return await client.updateRow(
        tableName,
        values as Record<string, unknown>,
        filter as Record<string, unknown>
      );
    } catch (error) {
      throw new Error(
        `Failed to update rows in ${tableName}: ${error instanceof Error ? error.message : 'Unknown error'}`
      );
    }
  },
});