Is there a way to add a table as an input?

Options
Alimama
Alimama Member
edited January 2023 in ? Working with APIs

I find myself updating a certain set of fields/columns in different tables repeatedly. These columns appear as the same names same types across these different tables. I would like to be able to write one function that accepts the “table name” and then simply update these columns/fields in the provided table instead of building one function for each table update.

e.g. I need to always edit start_date, end_date, ID, updated_at. Same fields are in the following tables:

employee, jobs, department etc.

I want a situation where I can provide these fields as inputs and the tables too as inputs. Such that the function takes the fields value provided and the edits the table provided, say, employees with them. If jobs table is provided, it updates jobs too with the same value provided for the fields. I don’t know whether the table name should be the input for the table or an object/schema of the the table type etc.

I know this might be almost impossible but would also appreciate another approach that avoids repeating same functions for each table. Thanks I’m advance.

Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @Alimama - you could definitely build this as a custom function! You could take advantage of Conditionals that would depend on your table_name input value...

    So each conditional would say

    IF table_input = table_1

    THEN edit record table_1

    IF table_input = table_2

    THEN edit record table_2

    etc...