How to build a Dynamic SELECT Query in Mule 4 to get data from Snowflake
I have a requirement to build a dynamic SELECT query which has to take any select number of attributes, any table name and any number of where conditions like a sample query hown below. The values in {} will be dynamic.
select {first_name,last_name} from {tableName} where {student_id=12345 and status='active'}
if first_name,last_name are not present, then it will be all (select * from). Where condition also may be empty.
I am thinking maybe I can handle the inputs to my API as below
{first_name,last_name} - payload {tableName} - uri param {student_id=12345&status=active}- query params
rest endpoint will look like this – (POST) with input payload as shown below
http://**************/{tableName}?student_id=12345&status=active
input payload
{ param1:first_name, param2 : last_name }
Also planning to add table names in property file and map them to variable tableName based on the incoming path or a parameter to avoid security breaches.
Could you please suggest if this is the right approach? Want to avoid any security breaches and also want to make it more generic API for reusability.
0 comments:
Post a Comment
Thanks